ラチェットパッケージを使用してチャットアプリケーションを作成しています。 共有ホスティングで「chat:serve」コマンドを実行するにはどうすればよいですか?私はコンソールラインなしでコマンドを実行する必要があります。Laravel:背景でカスタムアーティザンコマンドを実行する
Artisan::call('chat:serve');
またはこの: 私はこの試みた
$serve = new WSChatServer();
$serve->fire();
を、それは動作しません。 Webページはロードを停止しません。 この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],
];
}
}