CodeIgniter RESTful, async / background process

前端 未结 4 1760
悲&欢浪女
悲&欢浪女 2020-12-11 06:18

I\'m using codeIgniter RESTful API (https://github.com/philsturgeon/codeigniter-restserver) that return information (json format) to my android/iphone app.

There are

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 07:05

    I found a solution that works perfect for me because i don't expect any result value. If notification can't be send...i log it in my database.

    This is the function that i use to send "async" request (yes, This is not an asynchronous request, but it works how i'm looking for)

    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);
    }
    

提交回复
热议问题