2

I've a curl script that looks like this:

<?php

echo "hello";

$download_file = "http://www.myremotesite.com/api/download.php?autoupdate=1";

$temp_file = tempnam('/tmp','TEMP');

$ch2 = curl_init();

curl_setopt($ch2, CURLOPT_URL,            $download_file);
curl_setopt($ch2, CURLOPT_HEADER,         FALSE);
curl_setopt($ch2, CURLOPT_FAILONERROR,    FALSE);
curl_setopt($ch2, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch2, CURLOPT_TIMEOUT,        10000); 

$file = curl_exec($ch2);
curl_close($ch2);

$fp = fopen($temp_file, 'w');
fwrite($fp, $file);
fclose($fp);

?>

The problem is that the output on the page after execution looks like this:

hellohello

And from my testing I've narrowed it down to the $download_file URL. If I change that to , say, http://www.google.com, there is no issue.

Any idea on what my be causing this double output? It's happening in other situations too for different URLs. I really think it's something server based because this same setup works fine on other hosts.

Server Information Linux x-mirrors.com 2.6.26-2-openvz-amd64 #1 SMP Tue Jan 25 06:04:33 UTC 2011 x86_64 PHP Version 5.2.6-1+lenny10 Fast CGI Enabled

7
  • I feel like we're missing code here. Where's $ch1? Commented Oct 24, 2011 at 17:27
  • 3
    Nothing in that script would cause it to run twice, unless it was requested twice. Commented Oct 24, 2011 at 17:39
  • @ceejayoz it was there when I was seeing if the issue could be narrowed down to two CURL requests running in one script... you know just theory testing. $ch2 is what remained by the time I figured out what was causing it to print hello twice. Hey Marc, I agree. Nevertheless.... Commented Oct 24, 2011 at 17:41
  • how are you executing the script? Commented Oct 24, 2011 at 17:58
  • Hey Phill, at the moment, this script above is the code for a test.php, which I am running in a browser. Commented Oct 24, 2011 at 18:12

1 Answer 1

1

I had same problem. it's because of .htaccess file probably . if you use

   RewriteEngine On  
   RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

. check it without them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.