fputs()出现异常怎么办?
页面提示:
Assembly codeWarning: fputs() expects parameter 1 to be resource, boolean given in x.php on line 100Warning: feof() expects parameter 1 to be resource, boolean given in x.php on line 101Warning: fgets() expects parameter 1 to be resource, boolean given in x.php on line 102
提示的时候就是这三行不停的循环输出,大概有几十上百行吧,页面卡死,我直接关掉浏览器
也不是每次都如此,大部分都是正常的,只是偶尔碰到连接的时候会出现这样的错误异常
x.php文件:
PHP code $data = ""; $text = "xawasdf"; $server = "abc.com"; $fp = fsockopen($server, 43, $errNo, $errStr, 10); fputs($fp, $text. "\r\n"); //100行 while (!feof($fp)) { //101行 $data .= fgets($fp, 128); //102行 } fclose($fp);
请问这几行代码有没有修改的可能?
------解决方案--------------------$fp = fsockopen($server, 43, $errNo, $errStr, 10);
失败
应加上排错代码
------解决方案--------------------fsockopen根本就没有打开abc.com
------解决方案--------------------fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()). If the call fails, it will return FALSE
这么写 = =
$data = "";
$text = "xawasdf";
$server = "abc.com";
$fp = fsockopen($server, 43, $errNo, $errStr, 10);
if($fp)
{
fputs($fp, $text. "\r\n"); //100行
while (!feof($fp)) { //101行
$data .= fgets($fp, 128); //102行
}
fclose($fp);
}
------解决方案--------------------你fputs参数传成了空句柄,原因是fopen失败造成返回内容(fputs的参数)异常
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。