atwellpub
atwellpub

Reputation: 6010

CURL CURLOPT_URL is causing php script to run twice

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

Upvotes: 2

Views: 1773

Answers (1)

Mohsen Molaei
Mohsen Molaei

Reputation: 144

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.

Upvotes: 1

Related Questions