Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a site that has several users, basically I want to update all the users stats when users do something that affect stats for themselves and others.

Right now I am simply including the php file with include_once() and this works but takes more and more time as I get more users.

Is there a way I can run the files that make the updates without having the user wait for them to finish?

Thanks!
Posted

1 solution

I used something like this

PHP
$parts=parse_url('http://mysite.com/update.php'); //This is the file you want to run in the background

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

if (!$fp) {
} else {
    $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($parts['query'])."\r\n";
    $out.= "Connection: Close\r\n\r\n";
    if (isset($parts['query'])) $out.= $parts['query'];

    fwrite($fp, $out);
    fclose($fp);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900