What if an exception occurs in fputs? Page prompt: AssemblycodeWarning: fputs () expectsparameter1toberesource, booleangivenloud. phponline100Warning: feof () expectsparameter1toberesource, boolea fputs () what should I do?
Page prompt:
Assembly code
Warning: 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
When prompted, these three rows are repeatedly output. There may be dozens or even hundreds of rows. the page is stuck and I will directly turn off the browser.
This is not the case every time. most of them are normal, but this error occurs occasionally when you encounter a connection.
X. php file:
PHP code
$ Data = ""; $ text = "xawasdf"; $ server = "abc.com"; $ fp = fsockopen ($ server, 43, $ errNo, $ errStr, 10 ); fputs ($ fp, $ text. "\ r \ n"); // 100 rows while (! Feof ($ fp) {// 101 rows $ data. = fgets ($ fp, 128); // 102 rows} fclose ($ fp );
Are there any possible changes to these lines of code?
------ Solution --------------------
$ Fp = fsockopen ($ server, 43, $ errNo, $ errStr, 10 );
Failed
Error code should be added
------ Solution --------------------
Fsockopen does not open abc.com at all.
------ Solution --------------------
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
Write =
$ Data = "";
$ Text = "xawasdf ";
$ Server = "abc.com ";
$ Fp = fsockopen ($ server, 43, $ errNo, $ errStr, 10 );
If ($ fp)
{
Fputs ($ fp, $ text. "\ r \ n"); // 100 rows
While (! Feof ($ fp) {// row 101
$ Data. = fgets ($ fp, 128); // 102 rows
}
Fclose ($ fp );
}
------ Solution --------------------
The fputs parameter is passed as a null handle because fopen fails to cause the returned content (fputs parameter) to be abnormal.