I'm creating a cron job that runs outside of WordPress. From a development perspective, this makes it really easy to debug and create cleanup scripts or cron jobs, by just running a command like the following on the command line:
php myfile.php
My issue is that WordPress somehow delays all output... typically when you run php files like this the output is generated on your screen in real time.
Does anyone know how to prevent WP from delaying all the output until the end of the job? It's probably some simple parameter I'm missing when running the PHP file, or a constant of some kind, but I'm not sure.
In the following code, you'd expect to have a 1-second delay between each output, instead, I currently get all the info printed at the end, at once:
set_time_limit( 0 );
ini_set( "memory_limit", "64M" );
ob_start();
require_once( dirname( __FILE__ ) . '/wp-load.php' ); // you need to adjust this to your path
ob_end_clean();
global $wpdb;
$q = $wpdb->prepare ("SELECT * FROM wp_posts LIMIT 5");
$results = $wpdb->get_results ($q);
echo "found " . count ($results) . "\n";
foreach ($results as $post)
{
echo $post->post_title . "\n";
sleep(1);
}
echo "\n\ndone";