tags:

views:

576

answers:

4

I'm trying to upload data with POST to my webserver but sometimes cURL just stalls and causes PHP to use 100% CPU indefinitely.

I'm using the code below.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $URL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
curl_setopt($curl, CURLOPT_HEADER, true);
$page = curl_exec($curl);
curl_close($curl);

Any insight to what is causing or how to track this issue would be great.

A: 

Upgrade to the newest version of PHP, PHP 5.3.1.

If the problem still persists, and your server is running Windows, upgrade it to anything else, particularily a form of *NIX: a GNU/Linux distribution, a form of BSD, SunOS, etc...

If the problem persists even then, or you think Windows is a good OS for servers [1], the instructions to track the problem and send a bug report are over here: http://bugs.php.net/how-to-report.php

[1] Microsoft itself has to restart each machine behind microsoft.com every month.

Flavius
Ditching your OS because of a random CPU usage issue is a crazy idea. PHP runs fine on Windows, as many people can attest.
jvenema
Downvoting an answer which contains the answer to his question is not good karma either :PWhat I practically did was to tell him where the "bug" might be, how to fix it, and/or how to report it
Flavius
This is nonsense. Windows is not my first choice for a server OS either, but I there are numerous perfectly fine production PHP sites hosted on Windows without any problems. Suggesting to "upgrade" to a *nix because of an unidentified bug is daft.
Pekka
I am suggesting trying the code on another OS in order to identify the source of the bug: is it because of a windows-specific part in PHP, or is it general? Does it behave the same in the latest version of PHP? If so, which OSes. These are all questions to ask yourself when creating a bug report.
Flavius
I've just upgraded to the lastest PHP and the problem still exist. I have strace the process and getting this as a reponse:poll([{fd=3, events=POLLOUT, revents=POLLERR|POLLHUP}], 1, 0) = 1poll([{fd=3, events=POLLOUT, revents=POLLERR|POLLHUP}], 1, 1000) = 1poll([{fd=3, events=POLLOUT, revents=POLLERR|POLLHUP}], 1, 0) = 1poll([{fd=3, events=POLLOUT, revents=POLLERR|POLLHUP}], 1, 1000) = 1poll([{fd=3, events=POLLOUT, revents=POLLERR|POLLHUP}], 1, 0) = 1poll([{fd=3, events=POLLOUT, revents=POLLERR|POLLHUP}], 1, 1000) = 1
DramaGirl
Can you test it on a remote *NIX as well? As you were told, for others and for myself your code works. What OS/version are you using? Try compiling it with debug info as described in the link above, and submit a bug report.
Flavius
The server I'm testing the codes on are CentOS 4.x, the issue is indeed with CURL I believe, I went through the code and echo out the output before and after every CURL call and it stops after the CURL. I'm using Curl Version curl 7.12.1.
DramaGirl
A: 

Can you determine if it's related to a specific file? Perhaps there's something related to encoding, or upload length?

My first thought would be to at least determine if a specific file/set of files are causing the problem; write out the filenames (and perhaps content) and types before the upload, and the filename after it completes. That way you'll know exactly which files are causing the problem, and you can move on from there.

jvenema
+1  A: 

If it really is the actual curl "call" that hangs and performs 100% CPU, then that is a curl bug and you should probably consider upgrading your libcurl.

Daniel Stenberg
Is there a way to update libcurl without recompiling PHP? I'm using Yum to install so compiling from source would mess everything else up.
DramaGirl
I'm using curl 7.12.1.
DramaGirl
7.12.1 is truly ANCIENT so you really should upgrade that. And you should be able to upgrade without recompiling, but that's a completely different topic...
Daniel Stenberg
A: 

Perhaps the issue is with what you're specifying as the post data. Could you do a var_dump($postdata) right before your call to cURL and post the output here? cURL could be getting hung up on a typecasting/serialization issue, or your post data is simply invalid (and hopefully we can correct it!).

mattbasta