我正在使用棘轮包创建聊天应用程序。 如何在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],
];
}
}