Reputation: 183
I am writing a wordpress part of my site with php and am working on writing a cron that works within my wordpress site. I don't want to use wordpress cron cause it only executes when people come to your page so I would like to use cpanel cron but be able to reference a cached object in wordpress but I haven't used cpanel cron and don't know how to reference it completely with php. Can I make a cpanel cron job in php and have it run it hourly and cache the variable to be used by wordpress without wordpress running it everytime I load it when including the file in wordpress? Do I have to include all files in php to have the variable of use or does global variable in php is accessable in all php files? I'm kinda a newb when it comes to using cpanel, php, and wordpress. I know this is a lot to ask but I am greatly appreciate it.
Upvotes: 0
Views: 4676
Reputation: 183
I would like to have everyone know who is looking to make their own cron from wordpress to look here.
http://wpdailybits.com/blog/replace-wordpress-cron-with-real-cron-job/74
I appreciate everyones help but this is a great overview I've found.
Upvotes: 2
Reputation: 5582
First, like Marc B says, there aren't different crons. Consider a cron as a scheduled job. You want it to run at different times/days. The CPANEL gives an interface for you to run the cron.
Now, about specifying crons through cpanel... if you're on a shared host, usually, the host may restrict access to command line. Of course it would also depend on the kind of hosting package given to you. This is why the CPANEL interface exists. It is a safer way of specifying your job. Otherwise, a beginner may experiment and give a bad command that may make the system vulnerable.
Now, here's how you should specify your cron job.
Create your PHP file that you need to run on schedule.
Go through the cpanel interface to create the cron job. I hope you can find it.
Now in the space provided, enter something like this example:
php -q /home/myhost/public_html/myfolder/mycronjob.php
In the above, example, you're saying run the cron with PHP. The path to the file is specified with reference to the location in the drive. Don't worry this path (/home/myhost
) is not directly accessible by the public. This is how some hosts need you to specify the location. So you've got to check with your host or you may find a reference to it in the cpanel.
Now give the days/times to run it. There's a box or a group of boxes for this purpose. You may for example enter 0 5 * * *
and this will execute the job daily at 5:00AM.
I hope this helps :)
Upvotes: 0
Reputation: 22415
You can hook it into Wordpress cron, then add a cron job in cPanel to run a command like this:
curl http://mysite.com/wp-cron.php
Then you get to write it using wp-cron, and you know wp-cron will have a chance to run regularly, even if nobody visits the site.
Upvotes: 1