Skip to content

Commit 1373cb5

Browse files
authored
Improvements to cron scripts (OpenMage#2380)
1 parent 84fd844 commit 1373cb5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cron.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
1919
*/
2020

21-
// Change current directory to the directory of current script
2221
chdir(__DIR__);
23-
2422
require 'app/bootstrap.php';
2523
require 'app/Mage.php';
2624

@@ -29,8 +27,7 @@
2927
exit;
3028
}
3129

32-
// Only for urls
33-
// Don't remove this
30+
// Only for urls, don't remove this
3431
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
3532
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);
3633

@@ -43,9 +40,12 @@
4340

4441
umask(0);
4542

46-
$disabledFuncs = array_map('trim', explode(',', strtolower(ini_get('disable_functions'))));
47-
$isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
48-
$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
43+
$disabledFuncs = array_map('trim', preg_split("/,|\s+/", strtolower(ini_get('disable_functions'))));
44+
$isShellDisabled = in_array('shell_exec', $disabledFuncs)
45+
|| !str_contains(strtolower(PHP_OS), 'win')
46+
|| !shell_exec('which expr 2>/dev/null')
47+
|| !shell_exec('which ps 2>/dev/null')
48+
|| !shell_exec('which sed 2>/dev/null');
4949

5050
try {
5151
if (stripos(PHP_OS, 'win') === false) {
@@ -62,8 +62,8 @@
6262
$fileName = escapeshellarg(basename(__FILE__));
6363
$cronPath = escapeshellarg(__DIR__ . '/cron.sh');
6464

65-
shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -mdefault 1") . " > /dev/null 2>&1 &");
66-
shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -malways 1") . " > /dev/null 2>&1 &");
65+
shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -mdefault 1") . " &");
66+
shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -malways 1") . " &");
6767
exit;
6868
}
6969
}

0 commit comments

Comments
 (0)