fsockeropen() & file() problem.
| From: | php_list at citiz dot net | Date: | Mon, 26 Jun 2000 09:32:57 +0000 |
| Subject: | fsockeropen() & file() problem. | ||
| Groups: | php.dev php.dev php.dev | ||
| Request: | Send a blank email to php-dev+get-22338@lists.php.net to get a copy of this message | ||
Hello php-dev,
I have this code todo something:
while(true){
print "start download\n";
if ($Arr_Stock = file("http://stock.net/allstockdata.asp?page=1")){
print "download done\n"
/* some code to do write array $Arr_Stock */
}else{
print "download fail";
sleep(5);
}
}
This code it work good most time, but when remote server "stock.net" down This code it
print "start download",
and it hold run, not print "download fail" not return anything, I must kill this pid,
and restart it.
So I use follow code instead it:
while(true){
$fp = fsockopen("stock.net", 80, &$errno, &$errstr, 5); /* I think
"5" is time out when remote server down. */
if(!$fp) {
print "download fail";
sleep(5);
} else {
set_socket_blocking($fp, false);
fputs($fp,"GET /allstockdata.asp?page=1\n\n");
while(!feof($fp)) {
$Str_StockMsg .= fgets($fp,1024);
}
fclose($fp);
$Arr_Stock = explode("\n",$Str_StockMsg);
/* some code to do write array $Arr_Stock */
}
}
It work fine than first code, but still die sometimes, I find function set_socket_timeout()
in php3, I want try it, but in php4 this function not find.
Any have good idea ??
Please help me!
Sorry for my english so poor.
--
Best regards,
php