Ask for the phpfsockopen function return value and the following code. How can I determine if the fsockopen connection is successful? If fwrite fails, it will generate a large number of error messages in my space & nbsp; PHPWarning: fwrite (): suppliedargumentisnotavalidstreamresourceinhome2. I 'd like to join in and ask php fsockopen function to return the value.
Ask the following code. How can I determine if the fsockopen connection is successful?
If fwrite fails, a large number of error messages will be generated in my space.
PHP Warning: fwrite (): supplied argument is not a valid stream resource in/home2/
I want to add a judgment. if fsockopen fails, it will be skipped to avoid error execution of fwrite.
Thank you! Please help
$ Fp = fsockopen ("www.example.com", 80, $ errno, $ errstr, 30 );
If (! $ Fp ){
Echo "$ errstr ($ errno) \ N ";
} Else {
$ Out = "GET/HTTP/1.1 \ r \ n ";
$ Out. = "Host: www.example.com \ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
Fwrite ($ fp, $ out );
While (! Feof ($ fp )){
Echo fgets ($ fp, 128 );
}
Fclose ($ fp );
}
------ Solution --------------------
The code is correct. this is an example of the official PHP website. Paste your code.
In addition, you can try this way. if (get_resource_type ($ fp) = 'stream') fwrite ($ fp, $ out );
------ Solution --------------------
You have no judgment here. Add and exit.
If (! $ Fp ){
Echo "$ errstr ($ errno)
\ N ";
Exit;
} Else {
....
------ Solution --------------------
While ((! Ereg ('2014 OK ', $ banreturn ))&&(! Ereg ('1970 found', $ banreturn) & ($ attemp <2 )){
$ Connection = fsockopen ($ hostname, $ port, $ errno, $ errstr, $ timeout );
Stream_set_timeout ($ connection, 5 );
Fwrite ($ connection, $ headers); // error records are generated here, but not every time
Why don't I check whether it is enabled successfully before writing?