Firstly, my crontab trying to start the server each 15 minutes. The thing is, as you can see, sometimes it just stops without a reason. There is no problem with functions inside, my logs for errors empty and by that time there weren't any connections (develop stage). And i even commented them for testing, but it continued to happen.
Normally, when you trying to stop the server you see this:
2023-10-11 11:02:17 pid:2234040 Workerman[yii] stopping ...
2023-10-11 11:02:17 pid:2234040 Workerman[yii] has been stopped
And after, it says "already running", but it doesn't work actually (there is an error on client side about "CONNECTION REFUSED"). Only after manual stop through cmd it can be started again with proper work.
My server:
<?php
namespace backend\modules\sse\controllers;
use backend\modules\v1\models\User;
use Workerman\Worker;
use Workerman\Protocols\Http\Response;
use Workerman\Protocols\Http\ServerSentEvents;
use Workerman\Connection\TcpConnection;
use Workerman\Lib\Timer;
use Yii;
use Exception;
require_once '/var/www/www-root/data/www/myDomain/vendor/autoload.php';
class MainController extends \yii\console\Controller
{
private $cons;
private $worker;
public function actionRun()
{
$this->worker = new Worker('http://0.0.0.0:444);
$this->worker->name = 'sse';
$this->worker->user = 'www-data';
$this->worker->count = 1;
$this->worker->reloadable = true;
$this->worker->onMessage = function ($connection, $request) {
try {
if ($request->header('accept') === 'text/event-stream') {
$user = User::find()->where(['access_token' => $request->cookie()])->one();
if ($user) {
$response = new Response(
200,
[
'Access-Control-Allow-Origin' => rtrim($request->header('Referer'), '/'),
'Access-Control-Allow-Credentials' => 'true',
'Content-Type' => 'text/event-stream'
],
"\r\n"
);
$connection->send($response);
}
}
} catch (Exception $e) {
print_r($e->getMessage() . "\n");
}
};
Worker::$logFile = '/var/www/www-root/data/www/myDomain/backend/modules/sse/main.log';
Worker::$stdoutFile = '/var/www/www-root/data/www/myDomain/backend/modules/sse/custom.log';
Worker::$daemonize = true;
Worker::runAll();
}
}
Firstly, my crontab trying to start the server each 15 minutes. The thing is, as you can see, sometimes it just stops without a reason. There is no problem with functions inside, my logs for errors empty and by that time there weren't any connections (develop stage). And i even commented them for testing, but it continued to happen. Normally, when you trying to stop the server you see this:
But when that strange behaviour occurs, there is:
And after, it says "already running", but it doesn't work actually (there is an error on client side about "CONNECTION REFUSED"). Only after manual stop through cmd it can be started again with proper work.
My server:
Maybe i don't understand an issue, help me pls.