有人在 Laravel 队列作业中使用过静态变量吗?
我需要使用静态变量来累积传入的文件大小。
例如,如果总文件大小超过 1000mb,我需要立即向远程服务器发出请求。
[2017-06-18 07:59:44] local.ERROR: exception 'ErrorException' with message 'serialize(): "count" returned as member variable from __sleep() but does not exist' in C:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Queue\Queue.php:89 Stack trace: #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'serialize(): "a...', 'C:\\xampp\\htdocs...', 89, Array)
下面是我的队列代码。
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Log;
class SendToAPI extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $data = null;
private static $count = 0;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$count = $count + $this->data['file_size'];
if ($count > 1000)
{
// perform action
}
}
}