【发布时间】:2015-06-01 03:31:54
【问题描述】:
我为我的 ios 应用程序创建了一个 php 套接字。当我在完成所有工作之前使用终端启动它时,它运行良好..
问题出在第一个 socket_write。
写之前先检查一下服务器的socket是否在运行..$result = socket_connect($socket, $address, $service_port);
如果false 我需要重定向到页面http://localhost/api3/server.php 来启动套接字
public function __socket_write($text)
{
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
// if failed to connect means the server is currently down/not running
$this->__socket_start("http://localhost/api3/server.php");
}
// codes here not called api got an time out error as well, must have been redirected completely?
}
public function __socket_start($url, $status_code = 303)
{
header('Location: '.$url, true, $status_code);
}
服务器已成功启动,但看起来我需要异步调用__socket_start() 才能执行$this->__socket_start() 下面的代码,但我不知道如何,过了一会儿来自服务器的套接字再次关闭...
当我使用终端php server.php 启动套接字时,它不会断开连接。
提前谢谢你...
【问题讨论】:
标签: php sockets asynchronous