I am using ratchet for my websocket application.Below is my server code.
chat-server.php
error_reporting(0);
date_default_timezone_set('Europe/Berlin');
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$docRoot = "http://myshowcam.com/NewSite";
if (!isset($conn)) {
$host = "127.0.0.1"; // Hostname
$user = "root"; // Username Here
$pass = "xxxxx"; //Password Here
$db = "myshowcam"; // Database Name
$dbh = new PDO('mysql:dbname=' . $db . ';host=' . $host, $user, $pass);
}
$server=IoServer::factory(new HttpServer(new WsServer(new Chat())), 9000, "myshowcam.com");
$server->run();
To run the server i have used the nohup command as beolow
nohup php -q ratchet/bin/chat-server.php > ratchet_ws.log &
As the process stop working after few hour i have use a shell process to check if this server is running or not and if its not running will start the server again.
check_process.sh
while true
do
if pgrep php > /dev/null
then
echo Running
else
cd /mypath/project foldername/
nohup php -q ratchet/bin/chat-server.php > ratchet_ws.log &
fi
sleep 1;
done
Now instead of running the chat-server.php i am running this procss as below.
nohup sh chk_process.sh > check_process.log &
Now my chat-server.php running fine but its not responding after some hour.
Thank you for any help.