cron jobs or PHP scheduler

17,332

Solution 1

I think your concept needs to change.

PHP cannot schedule a job, neither can MySQL. Triggers in MySQL execute when a mysql query occurs, not at a specific time. Neither

This limitation usually isn't a problem in web development. The reason is because your PHP application should control all data going in and out. Usually, this means just the HTML that displays that data, or other formats to users, or other programs.

In your case you can think about it this way. The deadline is a set date. You can treat it as data, and save it to your database. When the deadline occurs is not important, it is that the data you have sent in your database is viewed correctly.

When a request is made to your application, check if the date of the deadline is in the past, if it is, then display that the project is closed - or update that the project is closed, just before display.

There really is no reason to update data independantly of your PHP application.

Usually, the only things you want to schedule are jobs that would affect your application in terms of load, or that need to be done only once, or where concurrency or time is an issue.

In your case none of those apply.

PS: I haven't tried PHPscheduler but I can guess it isn't a true scheduler. Cron is a deamon that sleeps until a given task is due in its queue, executes the task, then sleeps till the next one is due (at least thats what it does in the current algorithm). PHP cannot do that without the sockets and fork extensions, as special setup. So PHPscheduler is most likely just checking if a date for a task has expired, on each load of a webpage (whenever PHP executes a page). This is no different then you just checking if the date on the project has expired, without the overhead of PHPScheduler.

Solution 2

I would always go for a cron job for anything scheduling related.

The big bonus point is that you can echo info out as well and it get's emailed to you.

You'll find once you start using cronjobs, it's hard to stop.

Solution 3

cron does not exist, per se, in vista, but what does exist is the standard windows scheduling manager which you can run with a command line like "php -q -f myfile.php" which will execute the php file at the given time.

you can also use a port of the cron program, there are many out there.

if it is not critical to the second, any windows scheduling application will do, just be sure to have you PHP bin path in your PATH variable for simplicity.

Solution 4

For Windows CRON jobs I cannot recommend PyCron enough.

Share:
17,332
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I am using MYSQL as my database and PHP as my programming language.I wanted to run a cron job which would run until the current system date matches the "deadline(date)" column in my database table called "PROJECT".Once the dates are same an update query has to run which would change the status(field of project table) from "open" to "close".

    I am not really sure if cron jobs are the best way or I could use triggers or may be something else.Also I am using Apache as my web server and my OS is windows vista.

    Also which is the best way to do it? PHP scheduler or cron jobs or any other method? can anybody enlighten me?

  • Admin
    Admin over 14 years
    but hows it done on a web site? like commercial web sites do it with the help of cron jobs? is cron jobs the best way there too? because we can change hosts and may need to set it up everytime we change hosts.?
  • Mark L
    Mark L over 14 years
    You'd need to do it from a shell account on the host itself. If you SSH into your web server, pinpoint the php file you want to run, type crontab -e then add in the command, i.e. */5 * * * * /usr/bin/php /home/youraccount/website/file.php That should run it every five minutes or so. Search google for crontab generators and they'll help you fine tune the timings and generate the command strings for you. You would need to save the crontab when transfering between hosts: crontab -l > myct.txt and on the new server, I think it's crontab < myct.txt (or just copy and paste manually)
  • DavidScherer
    DavidScherer about 9 years
    For PHPScheduler to work properly, you need to initiate the scheduler to check for jobs regularly, which is done by placing some code on an active page. So if you get one page view per hour, you can schedule a job to run hourly, but not minutely. Not a solution I would recommend for jobs that are critical.