0

This is probably a very simple answer that I'm missing.

I have index.php and qeury.php in the same directory. Users visit index.php, which prints some info. It then needs to call qeury.php and exit, without waiting for query to finish running. Query just pings a server and then exits.

How does one accomplish this?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Xcelled194
0

Hi Xcelled194,

It depends what you mean by 'call query.php'.

You could include("query.php"); or you could redirect, header("location:query.php"); as a few examples depending on whether you want to keep control in index.php or pass control to query.php.

Edited by Zagga: n/a

0

What I was looking for is to basically spawn another process, then exit immediately. I don't care about the output (there is none), I just want the PHP file to run. I solved it like this:

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$lm = substr($url, 0, strlen($url)-strlen(strrchr($url, '/'))+1);
curl_post_async($lm . 'query.php');
die();

function curl_post_async($url)
{
   $post_string = '';

   $parts=parse_url($url);

   $fp = fsockopen($parts['host'],
       isset($parts['port'])?$parts['port']:80,
       $errno, $errstr, 30);

   $out = "POST ".$parts['path']." HTTP/1.1\r\n";
   $out.= "Host: ".$parts['host']."\r\n";
   $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
   $out.= "Content-Length: ".strlen($post_string)."\r\n";
   $out.= "Connection: Close\r\n\r\n";
   if (isset($post_string)) $out.= $post_string;

   fwrite($fp, $out);
   fclose($fp);
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.