Forum Moderators: coopster

Message Too Old, No Replies

Speeding up a PHP function

         

ocon

7:26 pm on Dec 14, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



I have a PHP page that loads a variable, performs some modifications to this variable, and seamlessly redirects the user to a new page.

<?php
$var=$_GET["variable"];
$var=strtolower($var);
header("Location: http://www.example.com/folder/".$var);
?>

Now, I want to add some advanced lookups with APIs for other websites and internal logging into MySQL. I put that in a seperate PHP file and set an include function.

<?php
$var=$_GET["variable"];
$var=strtolower($var);
include("/otherscripts.php?var=".$var);
header("Location: http://www.example.com/folder/".$var);
?>

The problem is, that makes the script take longer, as the script has to run through otherscripts.php and finish processing that file before redirecting the user. I can't bump up the header function over the include, or it wouldn't work properly.

Is there a way I can tell the PHP code to go start that, but not wait for any returns, just hurry up and finish waits on your plate?

rocknbil

9:11 pm on Dec 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look into fork() or if the extension is installed, pcntl_fork().

Spawn a child process for the include work, return immediate response in parent process.