diff --git a/application/Espo/Core/Utils/ScheduledJob.php b/application/Espo/Core/Utils/ScheduledJob.php index ab3160a515..4834a8b6eb 100644 --- a/application/Espo/Core/Utils/ScheduledJob.php +++ b/application/Espo/Core/Utils/ScheduledJob.php @@ -53,10 +53,10 @@ class ScheduledJob protected $checkingCronPeriod = '25 hours'; protected $cronSetup = [ - 'linux' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1', + 'linux' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BINARY} -f {CRON-FILE} > /dev/null 2>&1', 'windows' => '{PHP-BINARY} -f {FULL-CRON-PATH}', - 'mac' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1', - 'default' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1', + 'mac' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BINARY} -f {CRON-FILE} > /dev/null 2>&1', + 'default' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BINARY} -f {CRON-FILE} > /dev/null 2>&1', ]; protected $classFinder; @@ -105,7 +105,6 @@ class ScheduledJob $desc = $language->translate('cronSetup', 'options', 'ScheduledJob'); $data = array( - 'PHP-BIN-DIR' => $this->getSystemUtil()->getPhpBin(), 'PHP-BINARY' => $this->getSystemUtil()->getPhpBinary(), 'CRON-FILE' => $this->cronFile, 'DOCUMENT_ROOT' => $this->getSystemUtil()->getRootDir(), diff --git a/application/Espo/Core/Utils/System.php b/application/Espo/Core/Utils/System.php index 2f6ece1920..40f54a2c62 100644 --- a/application/Espo/Core/Utils/System.php +++ b/application/Espo/Core/Utils/System.php @@ -100,22 +100,11 @@ class System } /** - * Get path to PHP - * - * @return string + * Deprecated. Use getPhpBinary() */ public function getPhpBin() { - if (isset($_SERVER['PHP_PATH']) && !empty($_SERVER['PHP_PATH'])) { - return $_SERVER['PHP_PATH']; - } - - $phpBin = @exec('which php'); - if (!empty($phpBin)) { - return $phpBin; - } - - return defined("PHP_BINDIR") ? PHP_BINDIR . DIRECTORY_SEPARATOR . 'php' : 'php'; + return $this->getPhpBinary(); } /** @@ -125,7 +114,7 @@ class System */ public function getPhpBinary() { - return defined("PHP_BINARY") ? PHP_BINARY : 'php'; + return (new \Symfony\Component\Process\PhpExecutableFinder)->find(); } /** diff --git a/tests/unit/Espo/Core/Utils/SystemTest.php b/tests/unit/Espo/Core/Utils/SystemTest.php index ca6de732a7..a84943b045 100644 --- a/tests/unit/Espo/Core/Utils/SystemTest.php +++ b/tests/unit/Espo/Core/Utils/SystemTest.php @@ -86,12 +86,12 @@ class SystemTest extends \PHPUnit\Framework\TestCase $this->assertEquals($rootDir, $this->object->getRootDir()); } - public function testGetPhpBin() + public function testGetPhpBinary() { - $phpBin = @exec('which php'); + $phpBinary = (new \Symfony\Component\Process\PhpExecutableFinder)->find(); - if (isset($phpBin)) { - $this->assertEquals($phpBin, $this->object->getPhpBin()); + if (isset($phpBinary)) { + $this->assertEquals($phpBinary, $this->object->getPhpBinary()); } }