Download the PHP package smichaelsen/php-cron-scheduler without Composer
On this page you can find all versions of the php package smichaelsen/php-cron-scheduler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smichaelsen/php-cron-scheduler
More information about smichaelsen/php-cron-scheduler
Files in smichaelsen/php-cron-scheduler
Informations about the package php-cron-scheduler
PHP Cron Scheduler
This is a simple cron jobs scheduler inspired by the Laravel Task Scheduling.
Installing via Composer
The raccomended way is to install the php-cron-scheduler is through Composer.
Please refer to Getting Started on how to download and install Composer.
After you have downloaded/installed Composer, run
php composer.phar require peppeocchi/php-cron-scheduler
or add the package to your composer.json
How it works
Instead of adding a new entry in the crontab for each cronjob you have to run, you can add only one cron job to your crontab and define the commands in your .php file.
By default when you schedule a command it will run in background, you can overwrite that behavior by calling ->runInForeground()
method.
Jobs that should send the output to email/s are always set to run in foreground
Create your scheduler.php
file like this
Then add to your crontab
`
And you are ready to go.
Config
You can pass to the Scheduler constructor an array with your global config for the jobs
The only supported configuration until now is the sender email address when sending the result of a job execution
Jobs execution order
The jobs that are due to run are being ordered by their execution: jobs that can run in background will be executed first
Job types
After creating a new Scheduler
instance, you can add few type of jobs
-
->php('myCommand')
, execute aPHP
job. If you need you can set your ownPHP_BINARY
->raw('myCommand')
, execute a raw command in the shell, you can use this type if you want to pipe several commands likeps aux | grep memcached
->call('myFunction')
, execute your own function- you can optionally write your own interpreter (if you want you can do a PR to add the interpreter to this repo), just extend
GO\Job\Job
and define thebuild()
method, and an optionalinit()
if it requires to be initiated before running the command - eg. to define a bin path
Output
You can send the output of the execution of your cron job either to a file and an email address.
->output('myfile')
will overwrite that file if exists->output('myfile', true)
will append to that file (if exists) If you want to send the output to an email address, you need to send first the output to a file. That file will be attached to the email->output('myfile')->email('myemail')
You can pass an array of files or emails if you want to send the output to multiple files/emails ->output(['first_file', 'second_file'])->email(['myemail1' => 'Dev1', 'myemail2' => 'Dev2'])
Conditional
You can delegate the execution of a cronjob to a truthful test.
Schedule time
Scheduler
uses Cron\CronExpression
as an expression parser.
So you can schedule the job using the ->at('myCronExpression')
method and passing to that your cron expression (eg. * * * * *
) or one of the expression supported by mtdowling/cron-expression
Optionally you can use the "pretty scheduling" that lets you define times in an eloquent way. To do that you should call the ->every()
followed by
->minute()
, the job will be scheduled to run every minute->hour('02')
the job will be scheduled to run every hour. Defaultminute
is00
but you can override that with your ownminute
(in the example it will run every hour at minute02
)->day('10:23')
the job will be scheduled to run every day. Defaulthour:minute
is00:00
but you can override that with your ownhour:minute
->month('25 10:30')
the job will be scheduled to run every month. Defaultday hour:minute
is01 00:00
but you can override that with your ownday hour:minute
All versions of php-cron-scheduler with dependencies
mtdowling/cron-expression Version @stable
swiftmailer/swiftmailer Version @stable