Php 谷歌API内存耗尽错误

Php 谷歌API内存耗尽错误,php,laravel,google-api,adsense,Php,Laravel,Google Api,Adsense,我正在使用laravel 5.1 在谷歌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', '10

我正在使用laravel 5.1

谷歌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;
}
私有功能adsense\u更新($account\u id)
{
$output=“.::处理Adsense::.
”; 如果(!$account\u id) { $output.=“!!请添加您的ADSENSE帐户ID或发布者ID!!
”; 返回$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://'.$\u SERVER['http\u HOST'.]./adserver/public/adinfo\u refresh'); 如果(isset($_GET['code'])和&!会话('access_token')){ $client->authenticate($_GET['code']); $redirect='http://'.$\u服务器['http\u主机].$\u服务器['PHP\u SELF']; 标题('Location:'.filter_var($redirect,filter_SANITIZE_URL)); 会话(['access_token'=>$client->getAccessToken()]); AdInfoController::saveAccessToken(会话(“访问令牌”); $output.=“完成”; } 如果(isset($_GET['code'])) { return\Redirect::to('refresh'); } if(会话(“访问令牌”)){ $client->setAccessToken(会话(“访问令牌”); }否则{ $authUrl=$client->createAuthUrl(); } 如果($client->getAccessToken()){ 会话(['access_token'=>$client->getAccessToken()]); } if(isset($authUrl)){ $output.=“
”; } $service=new\Google\u service\u AdSense($client); //$client->setAccessToken($google\u access\u token); 如果($client->getAccessToken()){ $optParams=阵列( “度量”=>“AD\U请求\U RPM”, ); 试一试{ $report=$service->accounts\u reports->generate($account\u id,'today','today',$optparms); }捕获(例外$e) { //发生令牌错误 $this::deleteAccessToken(); //身份验证需要刷新 $this::adsense\u更新($account\u id); 返回; } if(isset(报告)){ $output.=“获得AdSense结果
”; //打印(报告); 如果(isset($report['rows'])和&array_key_存在(0,$report['rows'])){ $rpm=$report['rows'][0][0]; }否则{ $rpm=0; } $output.=“AdSense RPM:”.$RPM.“
”; DB::table('ads')->其中('id',1)->更新([ “最后每分钟转速”=>$rpm, “更新日期”=>日期(“Y-m-d H:i:s”) ]); $output.=“使用AdSense RPM更新数据库
”; } } $output.=“完成AdSense处理”


”; 返回$output; }

有什么解决方案吗?提前感谢您检查代码。例如,您可以在构造函数中创建对象A来创建对象B,然后该对象创建对象A。Boom!-记忆耗尽了!以前工作正常,今天出现了这个错误,只在一个实例中工作。实际代码是什么仍然检查您的代码,存在问题。增加内存限制不会解决任何问题。问题中添加了代码!请看一看