我正在使用棘輪包創建聊天應用程序。 如何在Shared Hosting上運行命令「chat:serve」?我需要運行沒有控制檯線的命令。 我嘗試這樣做:Laravel:在後臺運行自定義工匠命令
Artisan::call('chat:serve');
或本:
$serve = new WSChatServer();
$serve->fire();
,但它不工作。網頁永不停止加載。 我需要在後臺運行這個Artisan命令,它應該一直運行。我該怎麼做?沒有VPS託管可以做到這一點嗎?
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use App\Chat;
class WSChatServer extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'chat:serve';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Start chat server.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$port = intval($this->option('port'));
$this->info("Starting chat web socket server on port " . $port);
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
$port
);
$server->run();
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['port', 'p', InputOption::VALUE_OPTIONAL, 'Port where to launch the server.', 9090],
];
}
}