我正在使用 laravel 5.1
并在 Google Adsense API
中不断出现内存耗尽错误PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 38 bytes) in \vendor\google\apiclient\src\Google\Auth\OAuth2.php on line 240
已将内存限制增加到1GB
ini_set('memory_limit', '1024M');
尝试:
再次使用更大的
设置它ini_set('memory_limit','2048M');
并收到此错误
PHP Fatal error: Out of memory (allocated 1929641984) (tried to allocate 24 bytes) in \vendor\google\apiclient\src\Google\Auth\OAuth2.php on line 240
这是我的代码
private function adsense_update($account_id)
{
$output = ".:: Processing Adsense ::. <br />";
if (!$account_id)
{
$output .= "!! PLEASE ADD YOUR ADSENSE ACCOUNT ID OR PUBLISHER ID !!<hr>";
return $output;
}
$client = new \Google_Client();
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');
$client->setAccessType('offline');
$client->setAuthConfigFile(config_path().'/google_client_secrets.json');
// $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/adserver/public/adinfo_refresh');
if (isset($_GET['code']) && !session('access_token')) {
$client->authenticate($_GET['code']);
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
session(['access_token'=>$client->getAccessToken()]);
AdInfoController::saveAccessToken(session("access_token"));
$output .= "Done";
}
if (isset($_GET['code']))
{
return \Redirect::to('refresh');
}
if (session('access_token')) {
$client->setAccessToken(session('access_token'));
} else {
$authUrl = $client->createAuthUrl();
}
if ($client->getAccessToken()) {
session(['access_token'=>$client->getAccessToken()]);
}
if (isset($authUrl)) {
$output .= "<a class='login' href='" . $authUrl . "'>Google Login IN to Confirm Your Account</a><br />";
}
$service = new \Google_Service_AdSense($client);
// $client->setAccessToken($google_access_token);
if ($client->getAccessToken()) {
$optParams = array(
'metric' => 'AD_REQUESTS_RPM',
);
try{
$report = $service->accounts_reports->generate($account_id, 'today', 'today', $optParams);
}catch(Exception $e)
{
//An Token Error Occured
$this::deleteAccessToken();
// Authentication Needs to Refreshed
$this::adsense_update($account_id);
return;
}
if(isset($report)) {
$output .= "Got AdSense results<br />";
// print_r($report);
if (isset($report['rows']) && array_key_exists(0, $report['rows'])) {
$rpm = $report['rows'][0][0];
} else {
$rpm = 0;
}
$output .= "AdSense RPM: ".$rpm."<br />";
DB::table('ads')->where('id', 1)->update([
'last_rpm' => $rpm,
'updated_at' => date("Y-m-d H:i:s")
]);
$output .= "Updated Database with AdSense RPM<br />";
}
}
$output .= "AdSense Processing Done</p><hr>";
return $output;
}
任何解决方案?提前致谢