PHP code example of lizhibin / php-crond
1. Go to this page and download the library: Download lizhibin/php-crond 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/ */
lizhibin / php-crond example snippets
return [
//模式
'model' => 'daemon',
//PHP程序路径
'php' => '/usr/local/php-5.6.30/bin/php',
//日志文件
'log_file' => PROJECT_ROOT . "/logs/crond.log",
//主进程pid文件
'pid_file' => PROJECT_ROOT . "/logs/crond.pid",
//http接口服务,提供接口远程操作php_crond
'http_server' => [
'switch' => false,//是否启动http服务
'listen' => '127.0.0.1',
'port' => 8080,//监听端口
],
];
/**
* task配置文件
* 例子:
*/
return ['demo' => [
'daemon' => '* * * * * *',//秒 分 时 日 月 周
'filename' => 'sleep', //执行程序
'params' => ['5'],//执行程序参数
'single' => true,//如果进程在运行,则不执行,只保持一个进程
'standard_ouput' => '/dev/null', //标准输出
'error_output' => '/dev/null', // 错误输出
]];
return \Storage\Reader::registerTaskDirectory(__DIR__ . "/tasks");
return \Storage\Reader::registerTaskRemote($url, $serverId);
use Storage\Security\FixedCommandRule;
return [
//固定命令
new FixedCommandRule("sleep"),
];
shell
php bin/crond.php
shell
nohup php bin/crond.php > /dev/null 2>&1 &
javascript
{
"demo": {
"daemon": "0 * * * * *",
"filename": "echo",
"params": ["hello world!"],
"single": true,
"standard_ouput": "/dev/null",
"error_output": "/dev/null"
}
}