dongyihao1099 2015-09-23 15:09
浏览 264

PHP Curl - 来自服务器的空回复

I have an application which calls RESTful API using CURL POST request. The request is giving desired response if POSTFIELD data is of smaller size (<1024 bytes) but in case of large POSTFIELD the CURL execution only returns "Empty reply from server" error. API script does get executed as I can see only see partial data inserted in my database post which execution terminates abruptly.

I have already tried increasing default_session_timeout and memory_limit.

I checked Apache error logs but did not find anything logged in there as well. This is my code to consume REST API using CURL:

                $curl = curl_init($this->serviceUrl);
                $curl_post_data = (is_array($data)) ? http_build_query($data) : $data;
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_TIMEOUT, 420); 
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
                curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
                $curl_response = curl_exec($curl);

                if ($curl_response === false) {
                    $errorMessage = curl_error($curl);
                    $info = curl_getinfo($curl);
                    \Tools::writeErrorLog($errorMessage);
                    \Tools::writeErrorLog($info);
                }

                curl_close($curl);
                return $curl_response;

Is there any specific fix for this either in server configuration or the PHP code itself?

PHPINFO Details:

  • POST_MAX_SIZE - 8MB
  • Memory Limit - 256 MB
  • DEFAULT_SOCKET_TIMEOUT - 60
  • 写回答

1条回答 默认 最新

  • dongrong8972 2015-09-24 05:30
    关注

    I resolved the issue. Problem was of memory leak as I suspected. I revisited my API code and unset some unnecessary objects which freed memory for further process. @Timm and @Mihai Thanks for your help!!

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效