Great,  I'm glad it worked for you.  I've used pcntl for a few things since.

Be careful installing pcntl on a server you share with others, though.  A 
runaway fork can easily take down your whole server.

On Monday, June 3, 2013 9:44:19 PM UTC-4, Bill Zhang wrote:
>
> Thank you iateadonut. Your solution help us reduce the synchronization 
> time dramatically. From 7~8 hours to within 10 minutes.
>
> Best regads,
>
> Bill
>
> On Friday, December 16, 2011 12:23:44 PM UTC+10, iateadonut wrote:
>>
>> 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

--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to