PHP fsockopen 不返回任何内容
我正在修改 redis 数据库的 PHP db 包装器。
我的函数如下所示:
public function connect() {
$sock = @fsockopen('localhost', '6379', $errno, $errstr, 2);
if ($sock === FALSE) {
return FALSE;
}
else {
stream_set_timeout($sock, 2);
return $sock;
}
}
我想要做的是从包装器中的另一部分调用此函数:
if ($this->connect() !== FALSE) {
// Do stuff
}
当 fsockopen 不工作时,如何让我的 connect 函数发送 FALSE?
谢谢!
I am modifying a PHP db wrapper for the redis database.
Here's how my function looks:
public function connect() {
$sock = @fsockopen('localhost', '6379', $errno, $errstr, 2);
if ($sock === FALSE) {
return FALSE;
}
else {
stream_set_timeout($sock, 2);
return $sock;
}
}
What I want to do is to call this function from another part in my wrapper:
if ($this->connect() !== FALSE) {
// Do stuff
}
How can I get my connect function to send a FALSE when the fsockopen isn't working?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从
fsockopen()
页面向下一点(必须滚动到几乎到底部):我猜这是你的问题,我猜你必须进行测试读/写,看看它是否真的成功。
From a little ways down the
fsockopen()
page (have to scroll almost to the bottom):I'm going to guess that's your problem, I guess you have to do a test read/write to see if it was really successful or not.
尝试以下代码并查看是否按预期工作:
Try the following code and see if this works as intended:
你的函数前面有一个@,这将抑制错误。如果错误导致零回报,您将不会得到任何结果。删除 @ 并记录或显示任何产生的错误或警告。
You've got an @ in front of your function, which is going to suppress errors. If the error is causing zero return, you're not going to get anything. Remove the @ and log or display any resulting errors or warnings.
我知道现在回答可能已经太晚了。
但是,fsockopen 有点对“localhost”有问题..
尝试使用“127.0.0.1”nim 确保它可以连接。 ;)
I know it might be way late to answer.
But, fsockopen kinda has a problem with 'localhost'..
try using '127.0.0.1' n i m sure it will connect. ;)