Fputs () How to handle errors

Source: Internet
Author: User
Fputs () What happens when an exception occurs?
Page Tip:

Assembly Code
  
   Warning:fputs () expects parameter 1 to BES resource, boolean given in x.php on line 100warning:feof () expects parameter 1 To is resource, boolean given in x.php on line 101warning:fgets () expects parameter 1 to being resource, boolean given in X . PHP on line 102


The prompt is the three lines of the loop output, about dozens of hundreds of rows, the page stuck, I directly shut down the browser

It is not always the case, most of it is normal, but occasionally encounter the connection when the error will occur

x.php file:
PHP Code
  
               $data = "";            $text = "XAWASDF";            $server = "abc.com";            $fp = Fsockopen ($server, $errNo, $errStr, ten);            Fputs ($FP, $text. "\ r \ n"); 100 Rows            while (!feof ($fp)) {//101 line                $data. = Fgets ($fp, 128);//102 line            }            fclose ($FP);



Is there any possibility that these lines of code will be modified?

------Solution--------------------
$fp = Fsockopen ($server, $errNo, $ERRSTR, 10);
Failed
The wrong code should be added
------Solution--------------------
Fsockopen didn't even open abc.com.
------Solution--------------------
Fsockopen () Returns a file pointer which may is used together with the other file functions (such as fgets (), FGETSS (), FW Rite (), fclose (), and feof ()). If The call fails, it'll return FALSE


So write = =


$data = "";
$text = "XAWASDF";
$server = "ABC.com";
$fp = Fsockopen ($server, $errNo, $ERRSTR, 10);
if ($FP)
{
Fputs ($FP, $text. "\ r \ n"); 100 rows
while (!feof ($fp)) {//101 row
$data. = Fgets ($fp, 128); 102 rows
}
Fclose ($FP);
}
------Solution--------------------
You fputs argument to an empty handle because fopen failure causes the returned content (fputs parameter) to be abnormal
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.