Home > Backend Development > PHP Tutorial > fputs()出现错误怎么处理

fputs()出现错误怎么处理

WBOY
Release: 2016-06-13 13:23:02
Original
2243 people have browsed it

fputs()出现异常怎么办?
页面提示:

Assembly code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->Warning: fputs() expects parameter 1 to be resource, boolean given in x.php on line 100
Warning: feof() expects parameter 1 to be resource, boolean given in x.php on line 101
Warning: fgets() expects parameter 1 to be resource, boolean given in x.php on line 102
Copy after login


提示的时候就是这三行不停的循环输出,大概有几十上百行吧,页面卡死,我直接关掉浏览器

也不是每次都如此,大部分都是正常的,只是偶尔碰到连接的时候会出现这样的错误异常

x.php文件:
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->            $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);
Copy after login



请问这几行代码有没有修改的可能?

------解决方案--------------------
$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的参数)异常
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template