Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are cron jobs expensive ? Or are they basically visits?

Tags:

php

cron

I've been looking for the answer to this question for some time now and I find mixed answers. Are cron jobs heavy and expensive processes that consume a lot of resources? Or are they basically hits to that page (regardless of the script that executes when cron triggers it)

I intend to use several cron jobs for several sites. Let's say I have 3 different cron jobs that'll hit certain pages every minute for 10 sites. Does anyone have 10's or 100's of cron jobs like this in a triggering manner much like a browser hit (-wget...>/dev/null 2>&1)? If you do, do you experience additional load?

Further explanation; as you might know, WP-cron events do not take place if noone visits the WordPress site at the time of the scheduled event, until after someone comes along and triggers it. I have some not very active WordPress sites that I plan to carry out scheduled events and I am trying to get it right.

What do you think of the online cron services ? Do they exist just because most shared users are not allowed to create cron jobs? Or is it because cron jobs slow the server down and this way you can take some load off your server?

like image 606
Emin Özlem Avatar asked Apr 08 '14 12:04

Emin Özlem


2 Answers

Are cron jobs heavy and expensive processes that consume a lot of resources?

Not unless you make them like that. The cron process itself is very lightweight. All it's going to do is invoke your script. If your script is a heavy and expensive process, that has nothing to do with cron.

are they basically hits to that page

Kind of an odd metaphor, but I suppose so. The cron job executes the script. If that script is also used as a web page in some sense, then yes the two scenarios are comparable. (In fact, cron invoking the script is probably less resource-intensive than a web server invoking the script.) Though I recommend separating your webpage code from command-line code. (Unless your cron task is invoking an HTTP request to a page, such as using wget or something of that nature. In which case it has nothing to do with the "page" and is just invoking a command-line utility.)

What do you think of the online cron services? Do they exists just because most shared users are not allowed to create cron jobs? Or is it because cron jobs slow the server down and this way you can take some load off your server?

The former sounds more plausible. cron isn't resource-intensive. But it does require access that some shared hosting providers don't provide.

like image 189
David Avatar answered Nov 09 '22 03:11

David


Using a cron job to hit a web page to trigger application processes is not heavy.

It is a bit of a long winded approach but the act of fetching the page itelf (wget etc) is not heavy.

The heaviness of your application process is another matter entirely of course.

like image 39
edmondscommerce Avatar answered Nov 09 '22 05:11

edmondscommerce