我目前遇到的问题是我无法在websocket服务器中排队作业,我的目标是在指定的日期和时间内启动后台作业
我收到错误消息“发生了错误:不允许序列化'关闭'”
这是我目前的代码
<?php namespace App;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use App\Http\Controllers\WinIt;
use Cache;
use Carbon\Carbon;
use Session;
use Queue;
// Command Classes
use App\Commands\WinItInit;
class WebsocketServer implements MessageComponentInterface {
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
// Fire event when current date and time reaches $datetime
$datetime = '2016-02-10 15:48:08';
$serialization = Queue::later($datetime, new WinItInit($conn, $this->clients));
}
}
// The command to fire
<?php namespace App\Commands\WinIt;
use App\Commands\Command;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldBeQueued;
// Class Aliases
use DB;
use Input;
use Queue;
use Request;
use Response;
use Session;
use URL;
use Illuminate\Http\Exception;
use Illuminate\Support\Facades\Artisan;
// Custom Classes
class WinItInit extends Command implements SelfHandling, ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
private $from = null;
private $clients = null;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct($from = null, $clients = null)
{
$this->from = $from;
$this->clients = $clients;
$this->type = 'sample';
}
/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$data = array();
switch ($this->type)
{
case 'sample':
$datetime = date('Y-m-d H:i:s', time());
break;
}
foreach ($this->clients as $client)
{
$client->send(json_encode($data));
}
}
}