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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With