php fsockopen()无法建立连接

时间:2013-06-14 04:41:02

标签: php port fsockopen

我有关于fsockopen()的问题。

当我从http://tokudu.com/2010/how-to-implement-push-notifications-for-android编写代码时,它不起作用,我得到:

Warning: fsockopen() [function.fsockopen]: unable to connect to localhost:port
(No connection could be made because the target machine actively refused it. )
in C:\xampp\htdocs\PhpMQTTClient-master\SAM\MQTT\sam_mqtt.php on line 641
Offline

我试过this,但它无法解决我的问题 有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

如果连接成功,此函数 fsockopen("www.example.com", 80) 将返回流 resource

但是,如果连接失败,它会在您收到时生成错误:

您可以使用 @ operator 消除错误

$resource = @fsockopen("127.0.0.1","882");
// $resource will be stream resource object if call is successful
// $resource will be false if call  fails

避免引发和错误,并在连接失败时获取false作为返回值。