Reputation: 3787
The "upon command" part of the title is essential. I know how to set a cron job to run a PHP file at a pre-determined time schedule. What I need is similar in nature, but I think it requires a different technical solution.
I have an admin section, and when one of my admins logs in, they should be able to click a button which gets a PHP script to execute every 5 minutes for the next 2 hours.
Right now the button exists, and it calls a Javascript function which sends an AJAX request to the appropriate PHP file. It would make our lives a lot easier if the PHP function in the file could be told to run every 5 minutes from that moment until 2 hours have passed.
I'm aware that something similar could be done client-side by having Javascript repeat the request every 5 minutes. However, that doesn't help me a lot. An admin needs to be able to leave the site, send new requests to the same file with different parameters, all the while not interrupting the repeated execution of the PHP script.
So, I need some sort of server-side solution for this. Is that even possible? If so, what do I do?
I can share the client-side code but I don't think it really matters - the client side is a standard AJAX call; on the server side it's just this:
$par=$_GET['par']; //parameter received from AJAX
someFunction($par); //I need to modify the code so this function (please note there's a parameter) would run every 5 minutes for the next 2 hours
Upvotes: 0
Views: 1246
Reputation: 28409
A javascript solution would require that the admin would need to click the button then leave that page open for the next 2 hours which is far from ideal. I assume this is why you don't want this.
This is one method
If another admin clicks the button just overwrite that datetime for that job with the new value. The job will then always run every 5 minutes for 2 hours since the last click.
Upvotes: 4
Reputation: 18550
Use the at
shell command inside your php so it can call itself. Then use php to manage how many times its called or set them all up in one go
Upvotes: 0