|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23539 curl_exec seems to produce strange results
Submitted: 2003-05-08 01:21 UTC Modified: 2003-05-19 09:23 UTC
From: ramato at squiz dot net Assigned:
Status: Closed Package: cURL related
PHP Version: 4.3.2RC2 OS: Redhat Linux 7.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
48 - 31 = ?
Subscribe to this entry?

 [2003-05-08 01:21 UTC] ramato at squiz dot net
$url = '';
$ch = curl_init($url);
echo curl_error($ch);
curl_exec ($ch);
curl_close ($ch);

Produces random text output for the script.

The configure command was 

'./configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-config-file-path=/etc' '--enable-versioning' '--enable-inline-optimization' '--enable-memory-limit' '--with-xml' '--with-gd' '--with-jpeg-dir=/usr' '--enable-exif' '--with-bz2=/usr' '--enable-bcmath' '--with-openssl' '--with-zlib=/usr' '--enable-wddx' '--enable-ftp' '--with-curl=/usr' '--with-gettext' '--with-pspell=shared,/usr' '--with-mysql=shared,/usr' '--enable-gd-native-ttf' '--with-freetype-dir=/usr' '--with-ldap=shared' '--with-pgsql=shared' '--enable-mbstring' '--with-pear'

The strange thing is apache doesn't appear to segfault and nothing is logged to the php_error log file. Adjusting the error reporting to E_ALL doesn't change this.

phpinfo reports that curl is enabled and the curl information line in phpinfo has libcurl/7.10.4 OpenSSL/0.9.6b zlib/1.1.3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-08 03:29 UTC]
I can reproduce the problem.
 [2003-05-08 20:12 UTC]
The output (garbage) actually does not come from PHP but rather from curl_easy_perform(). I am guessing it is a result of some value not being initialized and random data is being treated as a 'real' value.
 [2003-05-12 06:39 UTC] daniel at haxx dot se
Are you saying that curl_easy_perform() behaves wrongly or that you use the output from it badly in the PHP/CURL glue code?

If it is the first, can you provide a small test code that shows the problem?

(libcurl maintainer)
 [2003-05-14 05:12 UTC] drhelper at mail dot ru
Snapshot php4-STABLE-200305140730 this bug
exist up to the point.

Any curl_exec() produces random text output.
 [2003-05-14 21:03 UTC]

I do not believe it is curl_easy_perform(), who is at fault here, but the strange text that I can see occurs every single time and definately is not printed by anything inside PHP. Unfortunately I am not fluent in libcurl source to give you much more information then that. I did however write a small scirpt that is the equivalent of the above code in C  (well, it does the same thing) and did not get any strange text.
 [2003-05-15 01:42 UTC] daniel at haxx dot se
Ok, I've seen users of PHP/CURL mention this before, and for some reason people tend to assume that the garbage is chunked transfer-encoding data (which is not true, since libcurl deals with the chunked data itself and hides that logic from the app).

One user says he solved the problem by using curl_setopt(curlopt_returntransfer,1) ( That could give you a hint of where to look for this.

Looking at the current ext/curl/interface.c code in CVS, I can only see a very minor bug that I think doesn't make any difference at this point. Patch for this follows here:

diff -u -r1.15 interface.c
--- interface.c	9 May 2003 01:10:18 -0000	1.15
+++ interface.c	15 May 2003 06:40:56 -0000
@@ -374,7 +374,7 @@
 	switch (t->method) {
-			PHPWRITE(data, size);
+			PHPWRITE(data, length);
 		case PHP_CURL_FILE:
 			return fwrite(data, size, nmemb, t->fp);
@@ -483,7 +483,7 @@
 			if (ch->handlers->write->method == PHP_CURL_RETURN) {
 				smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
 			} else {
-				PHPWRITE(data, size);
+				PHPWRITE(data, length);
 		case PHP_CURL_FILE:
 [2003-05-17 09:12 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

 [2003-05-19 09:23 UTC]
Now fixed also in the stable branch.

 [2004-01-01 17:34 UTC] hliu at ap dot org

I are suffering the curl problem as "The page cannot be displayed" based on the following code

$url = '';
$ch = curl_init($url);
echo curl_error($ch);
curl_exec ($ch);
curl_close ($ch);

Do you think I should ask my web hosting provider to fix it or is there some wrong on my php script?


 [2004-07-17 12:37 UTC] mahesh at mediaibc dot com
my apache server is not responding & hence the php pages result is not showing
what to do?
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 02 15:01:28 2023 UTC