Everytime a user visits a wordpress single-post page, the script update_comments.php is executed. It works the way it should, but the user won’t see the wordpress post, or anything for that matter, until the script has finished executing. I simply want to initiate the script without the user noticing a single thing. ignore_user_abort(true) is on in update_comments.php.
<?php
global $post;
$theid= $post->ID;
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
preg_match('/http(.*):\/\/(.*)\/(.*)/',
$url, $matches4);
$url = trim($matches4[2]);
preg_match('/(.*)\/(.*)/',
$url, $matches5);
$url = trim($matches5[1]);
$url = 'http://'.$url.'/update_comments.php?theid='.$theid;
$myresult = file_get_contents($url);
?>
One way would be to use a javascript callback:
Load the javascript at the bottom of the page and have the php file (ie
jsCommentsCallback.php) hit your$url, using$_GET['id']. If you need to do something with the content ofupdate_comments.php, you can package it up in JSON and send it back to the browser to insert into the page or whatever.