Hello
I’m wonderring if there is any way to run php script in backgroung (as “multithred”)
I tryied severall way but nothing seem to work
Could say me where i’m wrong ?
Methode 1 using socket:
My code:
$url = 'test.php';
$server='localhost';
$port=-1;
$conn_timeout=30;
$rw_timeout=86400;
$errno = '';
$errstr = '';
set_time_limit(0);
$fp = fsockopen($server, $port, $errno, $errstr, $conn_timeout);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
return false;
}
$out = "GET $url HTTP/1.1\r\n";
$out .= "Host: $server\r\n";
$out .= "Connection: Close\r\n\r\n";
stream_set_blocking($fp, false);
stream_set_timeout($fp, $rw_timeout);
fwrite($fp, $out);
The retunr is
Failed to parse address “localhost” (0)
I tryed with “http://heserver/” as host name but i got
Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? (123344144)
Methode 2 using CURL:
My code:
$curlUrl = 'http://heserver/test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curlUrl);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);
curl_exec($ch);
if(curl_errno($ch))
{
$error_message = curl_error($ch);
echo "<br>erreur:" . $error_message;
}
curl_close($ch);
the received error is:
Could not resolve host: heserver; Host not found
Actualy i got several long task (php script) to run in background, i’m aware to any way (but ajax) to dot it in exeputput.
Thanks in advance
Sebastien