ghaninia/shamsic

1.0.1 2022-07-20 19:27 UTC

This package is auto-updated.

Last update: 2024-04-20 23:37:29 UTC


README

art.png

Shamsic

Maybe it happened to you that you wanted to use CronJob in your project and you realized that you cannot manage the exact dates that are in the solar calendar.

For example, cron job allows you to run your script on specific days of the week, month! But CronJob supports the Gregorian calendar.It is useless or can be done with low accuracy for the solar date!

This package allows you to solve this problem inside the PHP code.

This package supports PHP 8.1+.

Install

Via Composer

$ composer require ghaninia/shamsic

How to use

You need to configure the cron job on the server ,The crontab command shown below will activate the cron tasks automatically every minutes:

* * * * * php output.php

'*' is a wildcard, meaning "every time". If you don't have any background about CronJob expressions and don't clear for you, follow the link crontab.

.---------------- minute (0 - 59) 
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) 
|  |  |  |  .---- day of week (0 - 6) 
|  |  |  |  |
*  *  *  *  *  command to be executed

The last three expressions of the cronJob are for the day of the month, the month and the day of the week. (Our main problem)

Now, open the file that will be executed by Cron Job (for this example output.php).

use GhaniniaIR\Shamsic\Schedule;

### At every minute on saturday in farvardin.
(new Schedule)
    ->call(function(){
        echo "test";
    })
    ->cron("* * * 1 2");

### At every minute on every day-of-week from saturday through thursday in khordad.
(new Schedule)
    ->call(function(){
        echo "test";
    })
    ->cron("* * * 3 1-5");

... 


### After writing all the schedules, you must run them
Schedule::run();

If you want to check that your expression is valid or not :

(new ExecuteExpression("* * * * *"))->isValid();