From 2186673b2a9e85db52b4f79a2b515af59b2fc451 Mon Sep 17 00:00:00 2001 From: yuri Date: Fri, 1 Feb 2019 16:58:47 +0200 Subject: [PATCH] find php executable --- application/Espo/Core/Application.php | 7 ++++++- application/Espo/Core/WebSocket/Pusher.php | 13 +++++++++++-- application/Espo/Core/defaults/systemConfig.php | 1 + websocket.php | 4 +++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 8941568c4e..0ce3b6f092 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -157,6 +157,11 @@ class Application $interval = $this->getConfig()->get('daemonInterval'); $timeout = $this->getConfig()->get('daemonProcessTimeout'); + $phpExecutablePath = $this->getConfig()->get('phpExecutablePath'); + if (!$phpExecutablePath) { + $phpExecutablePath = (new \Symfony\Component\Process\PhpExecutableFinder)->find(); + } + if (!$maxProcessNumber || !$interval) { $GLOBALS['log']->error("Daemon config params are not set."); return; @@ -178,7 +183,7 @@ class Application $toSkip = true; } if (!$toSkip) { - $process = new \Symfony\Component\Process\Process(['php', 'cron.php']); + $process = new \Symfony\Component\Process\Process([$phpExecutablePath, 'cron.php']); $process->setTimeout($timeout); $process->run(); } diff --git a/application/Espo/Core/WebSocket/Pusher.php b/application/Espo/Core/WebSocket/Pusher.php index d2368568cc..e2bee512a4 100644 --- a/application/Espo/Core/WebSocket/Pusher.php +++ b/application/Espo/Core/WebSocket/Pusher.php @@ -46,9 +46,12 @@ class Pusher implements WampServerInterface protected $connections = []; - public function __construct(array $categoryList = [], $isDebugMode = false) + private $phpExecutablePath; + + public function __construct(array $categoryList = [], $phpExecutablePath = null, $isDebugMode = false) { $this->categoryList = $categoryList; + $this->phpExecutablePath = $phpExecutablePath ?: (new \Symfony\Component\Process\PhpExecutableFinder)->find(); $this->isDebugMode = $isDebugMode; } @@ -157,7 +160,8 @@ class Pusher implements WampServerInterface $authToken = preg_replace('/[^a-zA-Z0-9]+/', '', $params['authToken']); $userId = $params['userId']; - $result = shell_exec("php auth_token_check.php " . $authToken); + $result = $this->getUserIdByAuthToken($authToken); + if (empty($result)) { $this->closeConnection($connection); return; @@ -171,6 +175,11 @@ class Pusher implements WampServerInterface $this->subscribeUser($connection, $userId); } + private function getUserIdByAuthToken($authToken) + { + return shell_exec($this->phpExecutablePath . " auth_token_check.php " . $authToken); + } + protected function closeConnection(ConnectionInterface $connection) { $userId = $this->getUserIdByConnection($connection); diff --git a/application/Espo/Core/defaults/systemConfig.php b/application/Espo/Core/defaults/systemConfig.php index 42c6e0fa90..05348ca183 100644 --- a/application/Espo/Core/defaults/systemConfig.php +++ b/application/Espo/Core/defaults/systemConfig.php @@ -115,6 +115,7 @@ return [ 'recommendedPhpParams', 'requiredMariadbVersion', 'recommendedMariadbParams', + 'phpExecutablePath', ], 'adminItems' => [ 'devMode', diff --git a/websocket.php b/websocket.php index 1fcfb38f00..d83bef24cf 100644 --- a/websocket.php +++ b/websocket.php @@ -32,10 +32,12 @@ if (substr(php_sapi_name(), 0, 3) != 'cli') die('Cron can be run only via CLI'); include "bootstrap.php"; $app = new \Espo\Core\Application(); + $categoryList = array_keys($app->getContainer()->get('metadata')->get(['app', 'webSocket', 'categories'], [])); +$phpExecutablePath = $app->getContainer()->get('config')->get('phpExecutablePath'); $loop = \React\EventLoop\Factory::create(); -$pusher = new \Espo\Core\WebSocket\Pusher($categoryList); +$pusher = new \Espo\Core\WebSocket\Pusher($categoryList, $phpExecutablePath); $context = new \React\ZMQ\Context($loop); $pull = $context->getSocket(\ZMQ::SOCKET_PULL);