cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Problems with curl after moving to slightly older version

From: Stephen Kay <sk_at_karma-lab.com>
Date: Wed, 23 Jul 2008 14:29:35 -0400

I have an issue where I am moving a web site from one host, which has:

php 5.2.6
cURL Information libcurl/7.15.3 OpenSSL/0.9.7a zlib/1.2.3 libidn/0.5.6

...to a new dedicated server at a different host, which has CentOS, and:

php 5.2.6
cURL Information libcurl/7.12.1 OpenSSL/0.9.7a zlib/1.2.1.2 libidn/0.5.6

So the new site has an older version of libcurl. They claim that this is the
latest version provided by the official CentOS repository, and the Atomic
Rocket Turtle user contributed repository.

The problem is, code that was working on the old server does not produce the
same results, and I have been unable to figure out why.

The code I am using is pretty darn simple:
======================================
    // initiate a curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $final_translate_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
        
    // get all pages in UTF-8
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Charset: UTF-8"));

    // set it to return the result, rather than display it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            
    // execute and receive the page text
$pagetext = curl_exec ($ch);

    // close the curl session and free up resources
curl_close ($ch);

    // diagnostics
$result = mb_detect_encoding($pagetext);
echo "encoding = " . $result . "<br>";

======================================

I receive the page back into a variable, and then I do a bunch of
post-processing on it.

I am using this mainly as a way to provide automatic translation into a
number of languages, by running it through yahoo's translation engine.

Problem 1:
As you can see, after ending the curl session, I am displaying the page
encoding just to check. On the old server, everything is utf-8 (like I
want). On the new server, no matter what I have tried, it's always "ASCII".
I've tried specifying the "Accept Charset" value in numerous ways, with line
ends, and without (based on various posts I have seen) - but it seems to
have no effect.

Problem 2:
In the old server, with libcurl 7.15.3, when the page is returned in the
variable, I can perform all of my post-processing and then echo it to the
screen. In the new server, with the older libcurl 7.12.1, it's almost like
it returns asynchronously - the post processing doesn't happen. Yet if I
remove the part in the code where the $pagetext variable is echoed to the
screen after post-processing, the page is blank, so I know that the page is
going into the variable. But the post-processing doesn't happen. Or perhaps
the page is displaying twice, and the first time it has the post-processing,
and the second time it doesn't although I don't know how to trap that. It's
difficult to explain, but the behavior is very weird.

Checking the curl changelogs, the only differences since 7.12.1 I noticed
that seemed like it might be relevant were:

Fixed in 7.14.0 - May 16 2005
Changes: modified default HTTP request headers

Fixed in 7.15.1 - December 7 2005
Changes: --max-redirs and CURLOPT_MAXREDIRS set to 0 limits redirects

I suppose it could also be some problem with the Apache settings on the new
server, but so far no luck there either.

Any ideas would be helpful. Thanks.

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-07-23