Cron Jobs or PHP Scheduler

I use MYSQL as my database and PHP as my programming language. I need to run a cron job that will run until the current system date matches the "deadline (date)" column in my "PROJECT" database table. Once the dates are the same, an update request should be executed that changes the status (field of the project table) from "open" to "close".

I'm not sure if cron job is the best way, or I can use triggers or maybe something else. I also use Apache as my web server, and my OS is Windows Vista.

And what is the best way to do this? PHP scheduler or cron jobs or any other method? can someone enlighten me?

+5
php mysql windows-vista cron scheduled-tasks
source share
6 answers

I think your concept should change.

PHP cannot schedule a task, and MySQL cannot. Triggers in MySQL are executed when a mysql query occurs, and not at a specific time. Neither

This limitation is usually not a problem in web development. The reason is because your PHP application must control all the data coming in and out. This usually means only HTML that displays this data or other formats for users or other programs.

In your case, you can think of it this way. The deadline is the set date. You can treat it as data and save it in your database. When the deadline does not matter, it is that the data that you sent in your database is viewed correctly.

When a request arrives in your application, check if the last date was in the past, if so, then show that the project is closed - or update that the project is closed before displaying.

In fact, there is no reason to update the data of your PHP application yourself.

Typically, the only things you want to schedule are tasks that will affect your application in terms of load, or only need to do this once, or where concurrency or time is a problem.

In your case, none of them apply.

PS: I have not tried PHPscheduler, but I can guess that this is not a real scheduler. Cron is a deamon that sleeps until a given task appears in the queue, performs a task, and then sleeps until the next one (at least what it does in the current algorithm). PHP cannot do this without sockets and fork extensions, as a special setting. Thus, the PHPscheduler most likely just checks to see if the deadline for the task has expired every time the webpage loads (whenever PHP executes the page). This is no different than just checking if a project has expired without PHPScheduler overhead.

+4
source share

I will always look for a cron job for any related planning.

The big bonus point is that you can also echo information and it will be emailed to you.

You will find that once you start using cronjobs, it is difficult to stop it.

+1
source share

cron does not exist, in fact, in Vista, but there is a standard Windows scheduling manager that you can run using the command line, such as "php -q -f myfile.php", which will execute the php file at a given time.

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

if this is not critical for the second, any Windows scheduling application will do, just make sure you use the PHP database path in your PATH variable for simplification.

+1
source share

For Windows CRON jobs, I cannot recommend PyCron enough.

+1
source share

how about phpscheduler..R aren't they better than cronjobs? I think crowns would be application independent, so it would be difficult if someone changed the host. I'm not sure though. It would be great if anyone could comment on this! Thanks!

0
source share

While CRON and Windows scheduled tasks are proven and correct ways to schedule tasks / tasks to run on a regular basis, there are times when running another scheduled task in CRON / Windows can become tedious. Namely, if you want users to plan the execution of some actions or for cases when you prefer simplicity / maintainability / portability / etc. Or all of the above.

In cases where I prefer not to use CRON / Windows for scheduled tasks, I embed a task scheduling system in the application. It still requires a CRON job or a Windows task. The idea is to save the details of the job in the database (job name, job properties, last run time, execution interval, something else important for your implementation). Then you plan to use the "Wizard" in CRON or Windows, which processes all your other tasks for you. You will need this basic work to work at least as soon as possible; if you want to be able to schedule tasks that run every minute, the main work should start every minute.

Then you can run each scheduled task in the background with PHP with minimal effort (if you want). On memory-limited systems, you can track memory usage or track PIDs (various methods) and limit N jobs to run at a given time,

I had great success with this method, however YMMV was based on your needs and your implementation.

0
source share

All Articles