How do Drupal Cron Tasks get activated in Linux? - php

In Linux, we use crontab to run automations. So far i know only that system cron can make automated tasks. Now i found out Drupal has the Crons also. But, the Drupal whatever is a bundle of script itself only.
I so far realized there is no way to make a PHP script to be up & running itself, without System Cron. And also it should not be.
So how does Drupal Cron get activated unless their tasks are registered in Linux/System crontab ?

Drupal cron is more of a psuedo-cron. It doesn't utilize the system crontab, or anything like that. Rather, it runs during the bootstrap process.
If your cron is set to 3 hours, for example, the bootstrap process (everytime you visit a Drupal page) will check to see if it's time to run the cron. If the time is >= 3 hours, the cron tasks will run.
This means that the cron runs are dependent on the visits your site gets. If no one is visiting your site, then the cron will not run.

Related

Why Wordpress's wp-cron checks schedule only on each page load?

In WordPress, I came across that wp-cron runs only on each page load and not as system cron which runs as per schedule even if no request comes. Can anyone explain this in detail? Also, is it true for all types of web servers?
Because wp-cron and system crontab - is different systems. WP Cron save scheduled event in database with time and for every load wp site, wp cron check database and do event if it needed. System cron works with system time and run scripts.
For all sites normally use system crontab. For Wordpress you also can use crontab and disable wp-cron in wp-config.php

Created a cron job in wordpress But the logs are displayed only when someone visits the page

In wordpress, I have worked to create a cron job.Currently, The Cron job displays the logs only when somebody visits the page. But, i want it to run without any page visit. I know that can be done. But how , that is what i dont know. Please guide me friends. I have used the function wp_scheduled_event
This is normal behaviour. Wordpress crons are not server crons, they depend of PHP to be executed, so it'll run only if someone visit your website.
From wp_schedule_event documentation:
The action will trigger when someone visits your WordPress site, if
the scheduled time has passed.
You'll need a server cron if you want to get through this limitation. Depends of your hosting, you may be able to configure a cron through the manager, or if you have SSH access on your server (so if it's not a shared hosting), execute this command :
crontab -e
It'll open your crontab file. Add this line inside to add a cron job:
*/30 * * * * php-cli -f /path/to/your/php/script.php
Replace with the correct path to your php script. This command will execute the script every 30 minutes - change this to whatever you need (read more).
If you're on a shared hosting and your manager doesn't allow you to create cron jobs, you could maybe use an online service like this one to execute your script.

Make a cron like schedule

My webhost doesn't have cron in it so I cannot set up cron jobs.
There is a certain php script in my website that should be ran every 24 hours to write daily logs etc.
I tried looking for external schedulers but I don't trust them.
How can I do such thing without cron?
I thought I maybe could use a mysql server and have an event or something?
I do NOT want it to rely on when a user uses my website due to the exact daily timing that I need.
Help is appreciated.
From a different host, set up a cronjob that does a wget of a page on your web-site. When that page is loaded, it does your script.

cron job or task scheduling in portable standard

i need to update/ empty my databases on a specific date. i've made it manually to be done by the admin. but if due to some reason, admin fails, then database won't be updated.
for doing this automatically, i've read about cron jobs or windows task scheduling.
but my project is under development now and i can't upload it to any site so that i can ping the specific page from other sites. my project is in USB, and i need to take to work, home, to friends or to wherever i can have access to a system. so creating a cron job or task schedule will not help as OS/ system is not constant.
how can i create a portable task scheduling?
or is there any other process to run the specific script and re-run after intervals whenever the server starts running?
i'm using xampp 1.8.2 in a USB under windows.

Is there a way in which a PHP or shell script can setup a cron job on a web server?

I am writing a component for Joomla and there is a specific task that requires an update to some stats every so often. I would like to setup a cron job to do this. The only problem is that requires the user to go and setup the cron to run the php update stats script.
On installation of the component how can I automatically setup a cron job for the user? Is this possible?
I've seen this implemented in the Akeeba backup pro component for Joomla, so I was hoping that I would be able to do the same thing.
Thanks
In theory you can create a crontab file and call it from PHP
<?php
exec("crontab $path_to_cron_file");
in practice it depends on wether the server (if you're on a shared hosting) allows you to do that.
All you need to do is write a line to the crontab file, generally stored in /var/spool/cron/crontabs/username. The cron daemon will see that the file modification time has changed and reload it automatically when it wakes up to do its checks
Another option (less desirable from a server load perspective but easier for users) would be to create a plugin that is run each time a visitor visits the site. It could check whether the process has been run in a specified time and then run it if it needs to be run.
iJoobi.com has another solution where they have set up a server to run cron tasks, which would then ping the specific URL on the website to kick off the process. (http://www.ijoobi.com/Help/jNews/jNews-Cron-Task.html)

Categories