Question

For me cronjob is a very new feature, so I would need some help from you guys.

I need to create a cronjob that will run at every 8 hours some php scripts.

    vend_1.php
    vend_2.php
    vend_3.php
    vend_4.php
    vend_5.php
    vend_6.php
    vend_7.php
    vend_8.php
    vend_9.php

Location of php scrips is within my theme on wordpress. So the path is :"/wp-content/themes/mythemename/vend_1.php"

I know that i need to have permissions so i set 0777 for all the files.
I already found how to run at every 8 hours:" 0 */8 * * * ".
I created the file cron.php within my theme path: /wp-content/themes/mythemename/cron.php

I don't know what i need to put in my cron.php. So I will be very happy is someone could help me.

Was it helpful?

Solution

create a file phpcron.sh with chmod 777 .

#!/bin/bash
for i in 1 2 3 4 5 6 7 8;
do php /var/www/html/project/path/to/vend_$i.php;
done;

and in the crontab just write :

0 */8 * * * root /path/to/phpcron.sh

thats it.

OTHER TIPS

If you already have a cron job set to execute /wp-content/themes/mythemename/cron.php every 8 hours, then you can do this:

Copy the following code into cron.php:

<?php

// Execute The vend_X.php scripts
for ($i = 1; $i <= 9; $i++) {
    include("/wp-content/themes/mythemename/vend_". $i .".php");
}

?>

The act of including those vend_x.php file will execute the scripts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top