Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > Remote File download is very slow
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 23rd November 23:18
shiplu.net
External User
 
Posts: 1
Default Remote File download is very slow



Hello folks,


I am using fsockopen and curl to download the file.
But the problem is its too slow.
Very very slow.
The code can be found on http://nopaste.info/55817730b3.html
I just put the method body.

Can any one help me on increasing the speed?

Thanks in Advance
--
http://talk.cmyweb.net/
http://twitter.com/shiplu
  Reply With Quote


 


2 23rd November 23:18
shiplu.net
External User
 
Posts: 1
Default Remote File download is very slow



Okay, I attached the code. Not everyone will click the paste bin link. :P

the code is a downloading function of a class.
the class has some methods need to be explained.
1) $this->debugMessage, it sends message to a call back function to a caller

2) $this->doCallback, sends the amount of bytes read to a call back function
to the caller\
3) $this->localfilename is the file where the remote file will be downloaded

4) $this->lfp is localfilepointer
5) read_chunk_size = 512
6) $headers is a predefined array of headers
7) $postdata is the url encoded data to send by post method.

Here is the code....
__________________________________________________ _______________________
$this->lfp = fopen($this->localfilename,"wb");

if($this->lfp===false){return false;}

if(function_exists('fsockopen')){
$pu = parse_url($this->download_url);
$request="POST {$pu['path']} HTTP/1.1\r\n";
$request.="Host: {$pu['host']}\r\n";
$request.="Content-type:
application/x-www-form-urlencoded\r\n";
$request.=implode("\r\n",$headers)."\r\n";
$request.="Connection: close\r\n";
$request.="Content-length: ".strlen($postdata)."\r\n\r\n";


$sock = fsockopen($pu['host'],80,$errno,$errstr);

fwrite($sock,$request);

$this->debugMessage("Headers Sent\r\n".$request);

fwrite($sock,$postdata);

$headers="";
do{
$headers.=fread($sock,128);
}while(strpos($headers,"\r\n\r\n")===false);

$pos = strpos($headers,"\r\n\r\n");
$headers = split("\r\n\r\n",$headers);
$headers = $headers[0];

$this->debugMessage("Headers recieved".$headers."\r\n");
$this->debugMessage("Downloading started. . .\r\n");
$content = substr($headers,$pos+4);
if($content!==false){
$this->doCallback(fwrite($this->lfp,$content));
}
while(!feof($sock)){

$this->doCallback(fwrite($this->lfp,fread($sock,$this->read_chunk_size)));

}
$this->debugMessage("Download finished\r\n");

fclose($sock);

}else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->download_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if(!empty($this->cookiefile)){
curl_setopt($ch, CURLOPT_COOKIEFILE,
$this->cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR,
$this->cookiefile);
}
curl_setopt($ch,CURLOPT_FILE,$this->lfp);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_exec($ch);
curl_close($ch);
}
fclose($this->lfp);
__________________________________________________ _______________________

--
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu
  Reply With Quote
3 23rd November 23:18
phpmail
External User
 
Posts: 1
Default Remote File download is very slow


2008/8/25 Shiplu <shiplu.net@gmail.com>:

What happens when you remove the first half of the if(), the bit that
relies on fsockopen(), and only use curl?

--

http://www.otton.org/
  Reply With Quote
4 23rd November 23:18
shiplu.net
External User
 
Posts: 1
Default Remote File download is very slow


Nothing works.
I was using curl actually.
It was hell slow.
Then I added the fsockeopen option.
Its slwo too.
now I am thinking to add socket_* functions.
But If dont know what is the problem how can I resolve it.
change scheme may not solve it.

--
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu
  Reply With Quote
5 23rd November 23:18
phpmail
External User
 
Posts: 1
Default Remote File download is very slow


2008/8/25 Shiplu <shiplu.net@gmail.com>:

Ok, lets start by getting some accurate data.

Here's a script that downloads a 6Mb MP3:

<?php

$fp = fopen( "temp1.mp3", "wb" );
$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, "http://gramotunes.com/Life_is_Long.mp3" );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_FILE, $fp );

curl_exec( $ch );

curl_close( $ch );

Save it as "download.php", and run the following two commands:

time php download.php
time wget http://gramotunes.com/Life_is_Long.mp3

I get

real 0m6.105s

and

real 0m5.927s

If your results are about equal, then the problem is not with PHP.

--

http://www.otton.org/
  Reply With Quote
6 23rd November 23:18
shiplu.net
External User
 
Posts: 1
Default Remote File download is very slow


They take same time.
let me tell you how my code works.
it download a file and in the same time it reports a progress by a call back
function.
this script is called from web. not console. it provides live debug
messages.
I'll give you a time wise debug log.

--
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu
  Reply With Quote
7 23rd November 23:18
shiplu.net
External User
 
Posts: 1
Default Remote File download is very slow


here are the log messages. see the timinings.

[2008-08-25 18:09:05.21780900]started downloading in
Live_In_Cuba_-_Louder_Than_War.part1.rar
[2008-08-25 18:09:05.60409200]Headers Sent
POST /files/108041147/1693469/Live_In_Cuba_-_Louder_Than_War.part1.rar HTTP/1.1
Host: rs246tl3.rapidshare.com
Content-type: application/x-www-form-urlencoded
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-language: en-us,en;q=0.7,bn;q=0.3
Accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: close
Content-length: 9
[2008-08-25 18:09:06.06572600]Headers recievedHTTP/1.1 200 OK
Date: Tue, 26 Aug 2008 00:09:05 GMT
Connection: close
Content-Type: application/octet-stream
Accept-Ranges: bytes
Content-Disposition: Attachment;
filename=Live_In_Cuba_-_Louder_Than_War.part1.rar
Content-Length: 104857600
[2008-08-25 18:09:06.06588900]Downloading started. . .
[2008-08-25 18:09:11.35468500]Downloaded 262144 bytes
[2008-08-25 18:09:15.26531200]Downloaded 524288 bytes
[2008-08-25 18:09:20.83112600]Downloaded 786432 bytes
[2008-08-25 18:09:26.26205800]Downloaded 1048576 bytes
[2008-08-25 18:09:31.78788500]Downloaded 1310720 bytes
[2008-08-25 18:09:37.27102800]Downloaded 1572864 bytes
[2008-08-25 18:09:42.72577600]Downloaded 1835008 bytes
[2008-08-25 18:09:48.08036500]Downloaded 2097152 bytes
[2008-08-25 18:09:53.46441000]Downloaded 2359296 bytes
[2008-08-25 18:09:58.91484500]Downloaded 2621440 bytes
[2008-08-25 18:10:04.42331800]Downloaded 2883584 bytes
[2008-08-25 18:10:10.00015700]Downloaded 3145728 bytes
[2008-08-25 18:10:15.30924700]Downloaded 3407872 bytes


see the speed?? Its too slow.


--
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Php 5 forum, Apache forum, Iis forum, Functions forum, Classes forum, Librarys forum, Bugs forum, Postgres forum, Mysql forum, Paradox forum, Ms sql forum, Configurations forum, Php.ini forum, Problems forum, Scripting forum, Css forum, General forums, Off-topic talk, Links, Extra forums, Php


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666