PHP code example of t4web / cron
1. Go to this page and download the library: Download t4web/cron library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
t4web / cron example snippets
'cron' => [
'log-directory' => 'data', // default: getcwd()/data
'phpPath' => 'php', // default: php
'scriptPath' => '/path/to/application/public/folder/', // default: getcwd()/public/
'jobs' => [
[
'id' => 'cron-job1',
'command' => 'index.php application cron-job1',
'schedule' => '* * * * *'
],
[
'id' => 'cron-job2',
'command' => 'index.php application cron-job2',
'schedule' => '* * * * *'
]
],
'timeout' => 3600 // default: null (without timeout)
]
sh
php index.php cron run
[2016-02-25 15:43:48] Job fail
Start: 2016-02-25 15:43:47
End: 2016-02-25 15:43:48
Execution time: 1 seconds
--Output:
1
2
3
--End output.
--Error:
PHP Fatal error: Call to undefined function Application\Controller\asd() in /storage/proj/1season/module/Application/src/Application/Controller/CronController.php on line 21
PHP Stack trace:
PHP 1. {main}() /storage/proj/1season/public/index.php:0
PHP 2. Zend\Mvc\Application->run() /storage/proj/1season/public/index.php:21
PHP 3. Zend\EventManager\EventManager->trigger() /storage/proj/1season/vendor/zendframework/zend-mvc/src/Application.php:314
PHP 4. Zend\EventManager\EventManager->triggerListeners() /storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:214
PHP 5. call_user_func:{/storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:490}() /storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:490
PHP 6. Zend\Mvc\DispatchListener->onDispatch() /storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:490
PHP 7. Zend\Mvc\Controller\AbstractController->dispatch() /storage/proj/1season/vendor/zendframework/zend-mvc/src/DispatchListener.php:93
PHP 8. Zend\EventManager\EventManager->trigger() /storage/proj/1season/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php:118
PHP 9. Zend\EventManager\EventManager->triggerListeners() /storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:214
PHP 10. call_user_func:{/storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:490}() /storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:490
PHP 11. Zend\Mvc\Controller\AbstractActionController->onDispatch() /storage/proj/1season/vendor/zendframework/zend-eventmanager/src/EventManager.php:490
PHP 12. Application\Controller\CronController->job1Action() /storage/proj/1season/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php:82
--End error.