Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run script at different times depending on conditions #77

Closed
jamminjames opened this issue Feb 11, 2019 · 3 comments
Closed

Run script at different times depending on conditions #77

jamminjames opened this issue Feb 11, 2019 · 3 comments

Comments

@jamminjames
Copy link

jamminjames commented Feb 11, 2019

I have a php script I want to run once a month or every day, depending on the value of certain values in a database.

I have no problem getting the variables into scheduler.php, but can't seem to write a function that will accomplish the above.

I've tried various ways of using the function lines you present, but can't get the result I need. What is the best way to do this?

It's not clear from the instructions if I should chain the command all into one thing, but maybe that's the key, like this, which I've seen in another cron scheduler:

$schedule = new Scheduler();

$schedule->php('filetorun.php')
	->at("10 10 10 * *"); 
        ->when(function() {
             if ($strcron) { return true; }
         });
	->output(['logs/cron_renewalemail.log'])
         ->run();

Thank you!

@rafaelmb
Copy link

rafaelmb commented Feb 22, 2019

is $strcron outside your closure? if it this you have to ineject it inside to use it properly

$schedule = new Scheduler();

$schedule->php('filetorun.php')
	->at("10 10 10 * *"); 
        ->when(function() use (strcron) {
             if ($strcron) { return true; }
         });
	->output(['logs/cron_renewalemail.log'])
         ->run();

@peppeocchi
Copy link
Owner

@jamminjames I think @rafaelmb got a point here, if you want to use a external variable in a Closure you have to specify it like the below

->when(function() use ($myExternalVariable) {
    # ....
})

I have to be honest I haven't tried your code yet but the when method works so there is no reason why in you code it shouldn't. Can you try the suggested solution and see if that works for you now?

thanks @rafaelmb!

@jamminjames
Copy link
Author

Yes, that works, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants