简体   繁体   中英

Problem with fwrite php

I am getting problem while using fwrite in php. the following code works in my local computer but gives error in server.

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if(!$fp) {
   echo 'Error: '.$errno.', '.$errstr;
} else {
   fwrite($fp, 'kool');
}

There is no error with fsockopen. it passes and gives no error. fwrite is not being able to write. it fails and returns no error only false

This is a permissions issue with the Apache/Nobody user accessing a remote file that it doesn't have permission to modify/read/write/execute.

You should also print the error message(s) for debugging

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if(!$fp) {
    echo "Error No: ".$errno."<br />\n";
    echo "Error Str: ".$errstr."<br />\n";
} else {
    fwrite($fp, 'kool');
}

如果在共享主机上,则很可能您的服务器不允许端口80上的出站连接。通常仅允许入站连接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM