{"id":41787726,"url":"https://github.com/2lovecode/cron-job","last_synced_at":"2026-01-25T04:32:09.002Z","repository":{"id":56938212,"uuid":"140089312","full_name":"2lovecode/cron-job","owner":"2lovecode","description":"php实现的秒级定时任务工具，基于workerman的库","archived":false,"fork":false,"pushed_at":"2019-07-03T06:28:27.000Z","size":20,"stargazers_count":24,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-01T00:39:54.802Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2lovecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-07T14:03:55.000Z","updated_at":"2023-10-06T12:41:47.000Z","dependencies_parsed_at":"2022-08-21T01:40:15.597Z","dependency_job_id":null,"html_url":"https://github.com/2lovecode/cron-job","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/2lovecode/cron-job","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fcron-job","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fcron-job/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fcron-job/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fcron-job/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2lovecode","download_url":"https://codeload.github.com/2lovecode/cron-job/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2lovecode%2Fcron-job/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28743498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T02:46:29.005Z","status":"ssl_error","status_checked_at":"2026-01-25T02:44:29.968Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-25T04:32:08.285Z","updated_at":"2026-01-25T04:32:08.982Z","avatar_url":"https://github.com/2lovecode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### 秒级定时任务工具，基于workerman库\r\n\r\n###### 以往我们实现定时任务主要依靠在服务器端配置crontab，但这种做法有几个弊端\r\n1) crontab只支持分钟级别，如果要实现秒级别的任务就必须写shell脚本实现。\r\n2) 如果代码部署上线后，需要更改或者添加新的定时任务，就必须登陆到服务器进行手动更改，耗时耗力且易出错。\r\n\r\n###### cron-job解决了主要的问题\r\n1) 通过使用秒级定时器(定时器具体实现因安装的扩展不同而有性能差异，但对我们的功能不影响)，实现了秒级别的定时任务。\r\n2) 定时任务的配置可以在配置文件中更改，在代码部署上线后，只要reload定时任务服务就可以，而且reload提供的是平滑重启，不影响正在执行的任务。\r\n3) 支持定时任务分发器和定时任务执行器部署到不同的服务器。\r\n\r\n###### 使用示例\r\n```\r\n    1.使用composer安装\r\n    在composer.json文件中的require下添加：\r\n    \"require\" : {\r\n    \t\t\"2lovecode/cron-job\": \"dev-master\"\r\n    }\r\n    执行composer install或composer update即可\r\n    2.test.php\r\n    \u003c?php\r\n    require_once \"../vendor/autoload.php\";\r\n    \r\n    $configDir = \"\";//指定配置文件路径,如果配置为空,默认使用default-config.php配置\r\n    \r\n    \\CronJob\\CronJob::run($configDir);//运行\r\n    \r\n    3.在cli模式下执行\r\n    php test.php start //debug模式运行\r\n    或\r\n    php test.php start -d //守护进程模式运行\r\n    \r\n    4.其它命令\r\n    php test.php stop //停止\r\n    php test.php stop -g\r\n    \r\n    php test.php reload\r\n    php test.php restart\r\n    \r\n    php test.php status\r\n    php test.php status -d\r\n    \r\n    php test.php connections\r\n    \r\n    可以通过php test.php查看命令帮助.\r\n```\r\n\r\n###### 配置文件参数 由php文件替换为json文件\r\n```\r\n    {\r\n      \"mode\" : \"both\",\r\n    \r\n      \"port\": \"8888\",\r\n     \r\n      \"host\": \"127.0.0.1\",\r\n      \r\n      \"processCount\": 4,\r\n      \r\n      \"execution-env\": \"\",\r\n      \r\n      \"stdout-log-file\": \"/tmp/cron-job-out.log\",\r\n      \r\n      \"stderr-log-file\": \"/tmp/cron-job-err.log\",\r\n    \r\n      \"cron\": {\r\n        \"echo \\\"ccc\\\"\": [\"*\", \"*\", \"*\", \"*\", \"*\", \"*\"]\r\n      }\r\n    }\r\n    \r\n    1.mode : required\r\n       - 指定模式:有3种trigger,actuator,both\r\n       - trigger,在当前服务器运行一个触发器\r\n       - actuator,在当前服务器运行一个执行器\r\n       - both,在当前服务器同时运行触发器和执行器\r\n    \r\n    \r\n    2.port : required\r\n        - 触发器监听的端口\r\n        \r\n    3.host : 执行器地址\r\n        - 执行器地址,仅在trigger和both模式下有效\r\n        \r\n    4.processCount : \r\n        - 进程数配置,仅在actuator和both模式下有效\r\n        \r\n    5.execution-env :\r\n        - 命令解释环境,为空则为shell命令\r\n        \r\n        \r\n    6.stdout-log-file :\r\n        - 标准输出记录文件,为空则不计录\r\n        \r\n    7.stderr-log-file :\r\n        - 错误输出记录文件,为空则不计录\r\n        \r\n    8.cron : required\r\n        - 具体的定时任务配置,相对于linux的crontab,添加了秒级支持.\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lovecode%2Fcron-job","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2lovecode%2Fcron-job","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2lovecode%2Fcron-job/lists"}