Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

$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

sudo service apache reload

while its in this hanged state the curl_exec immediately returns and I get my data. Im not a real web developer and more of a windows guy so any help would be greatly appreciated. :)

UPDATE I can see no error reporting from Curl since the process hangs. 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. I added the CURLOPT_VERBOSE option.

UPDATE 2: OK I can also run the post from curl commandline both from the host and the client. Worth mentioning is that my host is a virtual machine. Beginning to think its more of a network thing.

like image 571
PvPlatten Avatar asked Feb 11 '14 22:02

PvPlatten


1 Answers

OK I finally solved this stupid error with the help of this thread

PHP curl exec fail on php script same domain

The solution was to add:

session_write_close();

before the curl_exec

and then

session_start();

After. I hope I can help someone by writing it here.

like image 58
PvPlatten Avatar answered Sep 28 '22 22:09

PvPlatten