{"id":27627504,"url":"https://github.com/cron/cron","last_synced_at":"2025-04-23T13:54:57.386Z","repository":{"id":7216642,"uuid":"8523353","full_name":"Cron/Cron","owner":"Cron","description":"Cron API","archived":false,"fork":false,"pushed_at":"2024-11-13T21:07:25.000Z","size":152,"stargazers_count":354,"open_issues_count":2,"forks_count":70,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-11-13T22:19:01.287Z","etag":null,"topics":["cron","hacktoberfest","php","schedule"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cron.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-02T16:30:54.000Z","updated_at":"2024-11-13T21:04:38.000Z","dependencies_parsed_at":"2024-04-28T00:24:39.228Z","dependency_job_id":null,"html_url":"https://github.com/Cron/Cron","commit_stats":{"total_commits":112,"total_committers":18,"mean_commits":6.222222222222222,"dds":0.2589285714285714,"last_synced_commit":"ce28a372a67fab87d3782ca81b71c05e22befc15"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cron%2FCron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cron%2FCron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cron%2FCron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cron%2FCron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cron","download_url":"https://codeload.github.com/Cron/Cron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250444572,"owners_count":21431671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cron","hacktoberfest","php","schedule"],"created_at":"2025-04-23T13:54:56.584Z","updated_at":"2025-04-23T13:54:57.378Z","avatar_url":"https://github.com/Cron.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Cron\n====\n [![Packagist](https://img.shields.io/packagist/v/cron/cron.svg?style=flat-square)](https://packagist.org/packages/cron/cron)\n [![Build status](https://img.shields.io/github/actions/workflow/status/cron/cron/ci.yaml?style=flat-square)](https://github.com/cron/cron/actions/workflows/ci.yml)\n [![Quality](https://img.shields.io/scrutinizer/g/Cron/Cron.svg?style=flat-square)](https://scrutinizer-ci.com/g/Cron/Cron)\n [![Coverage](https://img.shields.io/scrutinizer/coverage/g/Cron/Cron.svg?style=flat-square)](https://scrutinizer-ci.com/g/Cron/Cron)\n [![Packagist](https://img.shields.io/packagist/dt/Cron/Cron.svg?style=flat-square)](https://packagist.org/packages/cron/cron)\n [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)\n\nThis library enables you to have only one general crontab entry that will trigger several different cronjobs that can be\ndefined through this library. The Cron library will decide if the job needs to run or not.\n\n**Attention**: make sure you set the server crontab job to a correctly chosen frequency because if there is for example\na cronjob defined in code to run every minute, your general crontab job needs to run at least every minute as well to\nwork properly.\n\nUse Case\n--------\n\nSay you need two cronjobs in your application. One that will write the contents of a folder to a log file, and one that\nwill empty the folder. This library enables you to create separate scripts (for example: cron.php) where you notify\nthe Cron library of the two cronjobs. After defining the Jobs with their specifics, they can be added to the resolver and\nthe run command can be given.\n\nYour server crontab could now look something like:\n```\n* * * * * /path/to/php /path/to/cron.php \u003e/dev/null 2\u003e\u00261\n```\n\nThe code example below is matched to this use case.\n\nCode example\n------------\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n// Write folder content to log every five minutes.\n$job1 = new \\Cron\\Job\\ShellJob();\n$job1-\u003esetCommand('ls -la /path/to/folder');\n$job1-\u003esetSchedule(new \\Cron\\Schedule\\CrontabSchedule('*/5 * * * *'));\n\n// Remove folder contents every hour.\n$job2 = new \\Cron\\Job\\ShellJob();\n$job2-\u003esetCommand('rm -rf /path/to/folder/*');\n$job2-\u003esetSchedule(new \\Cron\\Schedule\\CrontabSchedule('0 0 * * *'));\n\n$resolver = new \\Cron\\Resolver\\ArrayResolver();\n$resolver-\u003eaddJob($job1);\n$resolver-\u003eaddJob($job2);\n\n$cron = new \\Cron\\Cron();\n$cron-\u003esetExecutor(new \\Cron\\Executor\\Executor());\n$cron-\u003esetResolver($resolver);\n\n$cron-\u003erun();\n```\n\nCron currently only support triggering shell commands. This means you can trigger anything although it is highly encouraged\nnot to call web urls. But if you really need to here are some example commands.\n\n```\n* * * * * /usr/bin/lynx -source http://example.com/cron.php\n* * * * * /usr/bin/wget -O - -q -t 1 http://www.example.com/cron.php\n* * * * * curl -s http://example.com/cron.php\n```\n\nInstallation\n------------\n\nAdd the following to your project's composer.json:\n\n```bash\n$ composer require cron/cron\n```\n\n```javascript\n{\n    \"require\": {\n        \"cron/cron\": \"^1.0\"\n    }\n}\n```\n\nCrontab syntax\n--------------\n\nA CRON expression is a string representing the schedule for a particular command to execute.  The parts of a CRON schedule are as follows:\n\n    *    *    *    *    *    *\n    -    -    -    -    -    -\n    |    |    |    |    |    |\n    |    |    |    |    |    + year [optional]\n    |    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)\n    |    |    |    +---------- month (1 - 12)\n    |    |    +--------------- day of month (1 - 31)\n    |    +-------------------- hour (0 - 23)\n    +------------------------- min (0 - 59)\n\nEach of the parts supports wildcards (*), ranges (2-5) and lists (2,5,6,11).\n\nContributing\n------------\n\n\u003e All code contributions - including those of people having commit access - must\n\u003e go through a pull request and approved by a core developer before being\n\u003e merged. This is to ensure proper review of all the code.\n\u003e\n\u003e Fork the project, create a feature branch, and send us a pull request.\n\u003e\n\u003e To ensure a consistent code base, you should make sure the code follows\n\u003e the [Coding Standards](http://symfony.com/doc/2.0/contributing/code/standards.html)\n\u003e which we borrowed from Symfony.\n\u003e Make sure to check out [php-cs-fixer](https://github.com/fabpot/PHP-CS-Fixer) as this will help you a lot.\n\nIf you would like to help, take a look at the [list of issues](http://github.com/NoUseFreak/Cron/issues).\n\nRequirements\n------------\n\nPHP 5.5.0 or above\n\nAuthor and contributors\n-----------------------\n\nDries De Peuter - \u003cdries@nousefreak.be\u003e - \u003chttp://nousefreak.be\u003e\n\nSee also the list of [contributors](https://github.com/NoUseFreak/Cron/contributors) who participated in this project.\n\nLicense\n-------\n\nCron is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcron%2Fcron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcron%2Fcron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcron%2Fcron/lists"}