Phpfsockopen function return value

Source: Internet
Author: User
Tags ereg
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 (): suppliedargumentisnot ask the php fsockopen function to return values.
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?

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.