diff --git a/README.md b/README.md index 12ad0c2..2773a77 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,12 @@ You can enable web routes by setting `$cron->web=TRUE`. ### CLI path -By default, the script called asynchronously in CLI mode is `index.php` located in the current working directory. +By default, the script called asynchronously is `index.php` located in the current working directory. You may need to tweak this value if: * your web root differs from your app root (e.g: `index.php` resides in `www/` and starts with `chdir('..')`) -* you want to handle all the scheduling in a separate file (e.g: `cron.php` instead of `index.php`) +* all your scheduling is handled in a separate file (e.g: `cron.php` instead of `index.php`) Examples: @@ -226,9 +226,9 @@ $cron->web=TRUE;// enable web interface ### clipath -**Path of the script to call asynchronously in CLI mode** +**Path of the script to call asynchronously (default='index.php')** -Defaults to index.php in the current working directory. +Defaults to `index.php` in the current working directory. ```php $cron->clipath='htdocs/index.php';//relative to app root diff --git a/lib/cron.php b/lib/cron.php index c8efafc..ffd2518 100644 --- a/lib/cron.php +++ b/lib/cron.php @@ -16,7 +16,7 @@ class Cron extends \Prefab { public $web=FALSE; /** @var string */ - public $clipath; + public $clipath='index.php'; /** @var array */ protected $jobs=array(); @@ -87,12 +87,8 @@ function execute($job,$async=TRUE) { // PHP docs: If a program is started with this function, in order for it to continue running in the background, // the output of the program must be redirected to a file or another output stream. // Failing to do so will cause PHP to hang until the execution of the program ends. - $dir=''; - $file='index.php'; - if ($this->clipath) { - $dir=dirname($this->clipath); - $file=basename($this->clipath); - } + $dir=dirname($this->clipath); + $file=basename($this->clipath); if (@$dir[0]!='/') $dir=getcwd().'/'.$dir; exec(sprintf('cd "%s";php %s /cron/%s > /dev/null 2>/dev/null &',$dir,$file,$job)); @@ -193,12 +189,11 @@ function __get($name) { function __construct() { $f3=\Base::instance(); $config=(array)$f3->get('CRON'); - foreach(array('log','web') as $k) - if (isset($config[$k])) - $this->$k=(bool)$config[$k]; - foreach(array('clipath') as $k) - if (isset($config[$k])) - $this->$k=(string)$config[$k]; + foreach(array('log','web','clipath') as $k) + if (isset($config[$k])) { + settype($config[$k],gettype($this->$k)); + $this->$k=$config[$k]; + } if (isset($config['jobs'])) foreach($config['jobs'] as $job=>$arr) { $handler=array_shift($arr);