Ask PHP Fsockopen function return value
Ask the following code. How to tell if the Fsockopen connection is successful?
Because if it fails, fwrite will generate a lot of error messages in my space.
PHP warning:fwrite (): supplied argument is not a valid stream resource in/home2/
I want to add judgment, if Fsockopen fail to skip, avoid error execution fwrite
------Solution--------------------
The code is no problem, this is the PHP official website example. You should stick your code out.
Alternatively, you can try this, if (Get_resource_type ($fp) = = ' stream ') fwrite ($fp, $out);
------Solution--------------------
You are not judging here. You can just add a withdrawal.
if (! $fp) {
echo "$errstr ($errno)
\ n ";
Exit
} else {
....
------Solution--------------------
while (!ereg (' $ OK ', $banreturn) && (!ereg (' 302 Found ', $banreturn)) && ($attemp <2)) {
$connection = Fsockopen ($hostname, $port, $errno, $errstr, $timeout);
Stream_set_timeout ($connection, 5);
Fwrite ($connection, $headers); The error record is generated here, but not every time.
Why not first check if Open is successful or write?
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.