php - wordpress cron-jobs of off-wordpress file

190

I'm trying to run a PHP file that will create .txt file every 1 minute with cron jobs.

the following code of php is working:

$filename = 'test.txt'; 
$file = fopen($filename,"a+");
fwrite($file, "test");
fclose($file);

but that's just for testing. the actual script needs to get vars from wordpress (multisite) and for that I include wp-load.php and ms-load.php.

When I enter the script from browser it creates the txt files it needs to but when the cron jobs is trying to do so, it doesnt work and not giving me the txt files.

  • I tested the include path and it's currect.

The problematic code is:

chdir(dirname(__FILE__));
require_once( '../wp-load.php' );
require_once( '../wp-includes/ms-load.php' );
global $wpdb, $post; 
$blog_list = wp_get_sites( 0, 'all' );

$filename = 'test.txt'; 
$file = fopen($filename,"a+");
fwrite($file, "test");
fclose($file);
603

Answer

Solution:

Solved it by using CURL in the cron jobs.

People are also looking for solutions to the problem: php - file not uploading to pagodabox using codeigniter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.