CodeIgniter RESTful,异步/后台进程

jza*_*lla 5 php codeigniter response

我正在使用codeIgniter RESTful API(https://github.com/philsturgeon/codeigniter-restserver)将信息(json格式)返回到我的android/iphone应用程序.

有一个操作,我发送一些值,如果它是一切正常我返回200代码作为响应.

现在,我想以相同的方法添加新操作:使用APNS(Apple推送通知服务)和GCM(Google云消息传递)发送此修改的通知.

当我必须发送不超过3-5个通知时它运行良好,问题是APNS,因为我必须逐个发送此消息并且需要很长时间,因此我的应用程序收到超时异常(所有通知都是已发送但用户获取错误连接...)

我可以发送200代码响应,然后继续发送此通知吗?(像这样......)

function my_update_method_post(){
   //....GET my POST values
   update($data);
   $this->response(array('result'=>1),200));


   //Send Notifications
   ....
}
Run Code Online (Sandbox Code Playgroud)

提前致谢...

jza*_*lla 3

我找到了一个非常适合我的解决方案,因为我不期望任何结果值。如果无法发送通知...我会将其记录在我的数据库中。

这是我用来发送“异步”请求的函数(是的,这不是异步请求,但它按照我的要求工作)

function curl_post_async($url, $params)
{
    $post_string = http_build_query($params);
    $parts=parse_url($url);

    $fp = fsockopen($parts['host'],
        isset($parts['port'])?$parts['port']:80,
        $errno, $errstr, 30);

    if(!$fp)
    {
        //Perform whatever logging you want to have happen b/c this call failed!    
    }
    $out = "POST ".$parts['path']." HTTP/1.1\r\n";
    $out.= "Host: ".$parts['host']."\r\n";
    $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
    $out.= "Content-Length: ".strlen($post_string)."\r\n";
    $out.= "Connection: Close\r\n\r\n";
    if (isset($post_string)) $out.= $post_string;

    fwrite($fp, $out);
    fclose($fp);
}
Run Code Online (Sandbox Code Playgroud)