E
E
ex3xeng2015-11-24 20:10:50
PHP
ex3xeng, 2015-11-24 20:10:50

What is the best way to organize the task scheduler?

What is the best way to organize the task scheduler on the site?
I would like an alternative, bypassing the crowns.
There is an idea to create a file at the root and when accessing the script, it will pull it and see if more than an hour has passed since its creation, it will perform a number of specific tasks and create the file again, if not, it will simply go further.
While I see only 1 minus, this is the person on whom the task scheduling will work, for him the site may not open at all. Are there any other downsides? And how will this mechanism manifest itself when visiting from 5 tons of users, any ideas?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrew, 2015-11-24
@allard

I would advise you to use cron, or another task scheduler.
As for your idea, why try to complete your tasks when creating a page for the user ... Just give the page to the user, and then call your script with tasks through js ajax, and in ajax write timeout: wait for a response from the server for 1 ms, so that the script does not wait for tasks to complete, but simply ends. Look at jquery api.jquery.com/jquery.ajax.
More importantly, if you use sessions on the site, disable sessions in the file with the script for tasks, otherwise you will block all interaction with the user until the end of all operations by the script in the background.. .

S
Stalker_RED, 2015-11-24
@Stalker_RED

the site may not open for him at all
You can run your tasks in a separate process .
What didn't you like about the crown?

V
Vlad Zhivotnev, 2015-11-24
@inkvizitor68sl

The method you describe is used frequently. But it is wretched and CMS vendors who do this strongly recommend using system cron.
In Bitrix, this is called "cron on hits", for example.

P
Philipp, 2015-11-25
@zoonman

What you are about to do is bad. It is fraught with a race of conditions when 2 processes will try to generate one file, website timeout dumps for users and other unpleasant things like hanging Apaches, etc.
Proper scheduling of tasks implies user-independent and asynchronous non-blocking execution.
The correct approach is to use a task scheduler (in your case, cron) and a queuing system that executes tasks (e.g. based on gearman).
The approach with task queues allows you to simplify the process of generating files, isolate it from the rest of the site. For example, when you need to generate a price list, and then send it to 10k customers.
In your case, cron with a task specially written for it is the simplest and most effective solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question