-
-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How To Run Persitently on Ubuntu Server? #242
Comments
Use |
Thanks @walkor but when i try running that its not working anymore, look at this images |
I can't tell you what's the problem. Can you give a simple example to reproduce. |
@walkor i notice that its not running when i send message and insert via mysqli , when i disable the insert it works? is there any restriction on the mysql ? |
Do not initialize mysqli connections directly in the start file. Put the initialization of mysqli in onworker start like this. use Workerman\Timer;
$io = new SocketIO(9120);
$io->on('workerStart', function()use($io) {
global $mysqli;
$mysqli = new mysqli("localhost", "user", "password", "database");
// This is a heartbeat for mysql. Avoid mysql connection being closed by the MySQL server when the connection is inactive for a long time
Timer::add(50, function () {
global $mysqli;
$res = $mysqli->query('select 1');
// If the connection closed then reconnect.
if (!$res) {
$mysqli = new mysqli("localhost", "user", "password", "database");
};
});
});
$io->on('connection', function($socket)use($io){
$socket->on('chat message', function($msg)use($io){
global $mysqli;
$mysqli->query(...);
});
}); |
Thanks @walkor its working now 👍 |
On the subject of persistent running, can I sing the praises of pm2? It just works like a dream with phpsocket.io with lots of extra useful features. This is how I start it, and it's been rock solid. (start_io.php might need some modifications, IIRC) module.exports = { |
hi @walkor i would like to ask how to run this on a server and run it persistently? i run it on SSH then when i closed it the websocket is not running anymore.
i also run nohup php Server.php start >/dev/null 2>&1 & it runs in a day but in the next day the websocket is not working anymore.
The text was updated successfully, but these errors were encountered: