3

I have a PHP script that needs to be executed by the end of every month. How would I do that without using cron on Unix-like systems or Task Scheduler on Windows systems? Isn't there some built-in feature in php for this? Because using cron/scheduler is not that much portable way IMO.

6
  • Answer is "no" - this is what cron / task scheduler are for. The only other option is to run when triggered by another PHP script that you hope gets run by a user at the right time. Commented Sep 1, 2012 at 11:32
  • That's what cron and other scheduling method are there for? Have you looked at cron, its really simple. Commented Sep 1, 2012 at 11:32
  • yes i have, but I don't want my clients to perform any manual work to setup a simple script on server. Commented Sep 1, 2012 at 11:33
  • You might want to use MySql then: dev.mysql.com/doc/refman/5.1/en/events.html Commented Sep 1, 2012 at 11:35
  • @hakra interesting. Can it trigger execution of a php script or is it just limited to inside-the-database usage? Commented Sep 1, 2012 at 11:38

3 Answers 3

4

The only other way is by triggering it when the website is loaded. For example, you'd store the time the script was last run. Then every time a page is loaded, you'd check if it's time to run it. If so, then you would run it as part of the page load. Of course, this depends on (1) the task being a very quick one, and (2) that the task doesn't have to be run exactly on schedule, down to the second. This is basically how wp_cron() works in Wordpress.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. but then again, I am dependent on someone to load the page first.
3

Php is just a scripting language, not a process that is aware of time and may trigger events at desired moments.

Once you settle in a server, you don't have to worry about portability: migrating to another place won't be an automatic process because the environment could be very different.

So stick with cron, or write yourself a OS-agnostic layer.

Comments

1

In the system i worked on, i had a little module that had the last running of the script saved, and on every running of the main script, it checked, if the script shouldn't have been run. In case it should have, it did before anything else executed, so the system had the right data anyway, even if the periodical script wasn't run "on time". It also checked if the script shouldn't have been run more than once, and ran it several times, if needed. A bit crude, but produces the right results without anything but PHP/mysql.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.