My problem I'm sure it's easier but I didn't find a lot of documentation about it.
I'm using a SoapService and I'm making some request at it. This is working great but sometimes the server load it's too high and I cannot wait 10-20 seconds to have an answer, so it's better for me to give back an answer like "Server it's overload try later...".
I read how to do this and the only way I found it's to use concurrency, it's seems normal so I thought about creating a child process who it's calling the SoapService and a father who it's waiting some time and if the time exceed it have to give me back an error.
For the theory I think nothing is wrong, or I'm completly mistaken ?
For the code the way I found to do this in php is this one:
Code: Select all
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// I'm the father
pcntl_wait($status);
} else {
// I'm the crazy son
$result = __soapCall();
}
I try this but it didn't seems to work form me:
Code: Select all
//Code inside the parent part
$start = microtime(true);
$find = false;
while ( !$find && $start + 10 > microtime(true)){
pcntl_wait($status, WNOHANG);
if(isset($status)
$find = true;
}
if(!find)
throw new Exception("Server overload, try in few minutes");
Thanks a lot,
Regards,
Xavier Delcour