Thanks,

I did it with pcntl_fork.  (had a lot of different advice on this -
yours turned out to be the best)

The only problem is that it is consistently triggering Captcha's
(except one doing them one at a time, which takes forever).  How do I
deal with these?



Here is the code.  I will post it in the other discussion groups where
I gave advice pertinent on CrossClient Reports after I complete this
taking care of Captcha's.





<?php

error_reporting(E_STRICT | E_ALL);

// You can set the include path to src directory or reference
// AdWordsUser.php directly via require_once.
// $path = '/path/to/aw_api_php_lib/src';
include('../definedb.php'); //
include('./accountsArray.php'); //sets $adwordsAPIpath, uses $selector
= new ServicedAccountSelector(); to make an array of all accounts
//$accountsArray = array('4503399530');
//print_r($accountsArray);exit;
$path = $adwordsAPIpath.'/../../live_api2/src/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
require_once 'Google/Api/Ads/AdWords/Util/ReportUtils.php';

  // Get AdWordsUser from credentials in "../auth.ini"
  // relative to the AdWordsUser.php file's directory.
  $user = new AdWordsUser();
        //$user->SetClientId($customerId);

  // Log SOAP XML request and response.
  $user->LogDefaults();

  // Load ReportDefinitionService so that the required classes are
available.
  $user->LoadService('ReportDefinitionService', 'v201109');

  // Create selector.
  $selector = new Selector();
$selector->fields = array('ExternalCustomerId',
'AccountDescriptiveName', 'PrimaryUserLogin', 'Date', 'Id', 'Name',
'Impressions', 'Clicks', 'Cost');
  //$selector->predicates[] =
      //new Predicate('Status', 'IN', array('ENABLED', 'PAUSED'));

  // Create report definition.
  $reportDefinition = new ReportDefinition();
  $reportDefinition->selector = $selector;
  $reportDefinition->reportName = 'Campaign performance report #' .
time();
  $reportDefinition->dateRangeType = 'LAST_7_DAYS';
  $reportDefinition->reportType = 'CAMPAIGN_PERFORMANCE_REPORT';
  $reportDefinition->downloadFormat = 'CSV';
  $reportDefinition->includeZeroImpressions = FALSE;

  $options = array('version' => 'v201109', 'returnMoneyInMicros' =>
FALSE);

$pids = array();

$j = 0;

for ($i=0; $i<count($accountsArray); $i++) {

        if($j==10) { echo $j." ---\n"; $j=0; }

        $pids[$i] = pcntl_fork();

  if(!$pids[$i]) {

    // child process

        try {
  // Get AdWordsUser from credentials in "../auth.ini"
  // relative to the AdWordsUser.php file's directory.

        $customerId = $accountsArray[$i];

        $user->SetClientId($customerId);

        $fileName = "7days-".$customerId.".csv";
        $path = dirname(__FILE__) . '/../reports/7days/' . $fileName;

  ReportUtils::DownloadReport($reportDefinition, $path, $user,
$options);

  printf("Report with name '%s' was downloaded to '%s'.\n",
      $reportDefinition->reportName, $fileName);

  } catch (Exception $e) {
  print $e->getMessage();
}

    exit();
  }
        $j++;
        }






On Dec 15, 9:55 am, Kevin Winter <kevin.win...@google.com> wrote:
> Hi,
>   I'm not very familiar with PHP, but I believe one suggested approach is
> to use pcntl_fork to spawn extra processes and handle multiple concurrent
> report downloads that way:http://php.net/manual/en/function.pcntl-fork.php
>
> - Kevin Winter
> AdWords API Team
>
>
>
>
>
>
>
> On Wednesday, December 14, 2011 11:33:59 PM UTC-5, iateadonut wrote:
>
> > How do you suggest requesting 10 reports at a time (from an array of
> > 300 customerId's) using php?  or is this impossible?
>
> > On Dec 12, 12:33 pm, Kevin Winter <kevin....@google.com> wrote:
> > > Hi,
> > >   Given that AdHoc reports cost 0 units, the cost of requesting the
> > report
> > > to you as a developer is the CPU cycles (and IO) required to request it.
> > >  The cost to us from a server perspective is a bit more.  However, if you
> > > as a developer don't know at report time whether or not there is data to
> > > request, it makes sense to request it anyway.  Yes, go ahead and request
> > > the report anyway.
>
> > > - Kevin Winter
> > > AdWords API Team

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Reply via email to