简体   繁体   English

对POST执行https时,Curl挂起了我的Apache服务器

[英]Curl hangs my apache server when doing POST to https

I have this very weird issue with curl, when I do a post request to my ubuntu apache server the apache server hangs, if I debug my php code I can see that 我对curl有一个非常奇怪的问题,当我向ubuntu apache服务器发出发布请求时,apache服务器挂起了,如果我调试php代码,我可以看到

$fp = curl_exec($ch);

Never returns. 永不归来。 I think the actual post request is correct because I can successfully do the same POST request with postman. 我认为实际的发布请求是正确的,因为我可以与邮递员成功地执行相同的发布请求。

Below are my curl options : 以下是我的卷曲选项:

$ch = curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER , 0);
curl_setopt($ch,CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$testHeader);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
$fp = curl_exec($ch);

One weird thing is that if im quick, and reload my apache server 一件奇怪的事情是,如果我很快,然后重新加载我的apache服务器

sudo service apache reload

while its in this hanged state the curl_exec immediately returns and I get my data. 当curl_exec处于这种挂起状态时,它立即返回,我得到了我的数据。 Im not a real web developer and more of a windows guy so any help would be greatly appreciated. 我不是一个真正的Web开发人员,更不是Windows的家伙,所以任何帮助将不胜感激。 :) :)

UPDATE I can see no error reporting from Curl since the process hangs. 更新由于进程挂起,我看不到来自Curl的错误报告。 It never comes to the point where it can give me the error. 从来没有到可以给我错误的地步。 When I reload the apache server the request returns and then there are no errors reported. 当我重新加载apache服务器时,请求返回,然后没有错误报告。 I added the CURLOPT_VERBOSE option. 我添加了CURLOPT_VERBOSE选项。

UPDATE 2: OK I can also run the post from curl commandline both from the host and the client. 更新2:好的,我也可以从主机和客户端从curl命令行运行该帖子。 Worth mentioning is that my host is a virtual machine. 值得一提的是,我的主机是一台虚拟机。 Beginning to think its more of a network thing. 开始更多地将其视为网络事物。

OK I finally solved this stupid error with the help of this thread 好了,我终于在这个线程的帮助下解决了这个愚蠢的错误

PHP curl exec fail on php script same domain PHP curl执行失败在相同域的php脚本上

The solution was to add: 解决方案是添加:

session_write_close();

before the curl_exec 在curl_exec之前

and then 然后

session_start();

After. 后。 I hope I can help someone by writing it here. 我希望我可以在这里写一些东西来帮助别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM