473,569 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP File Transfers ending early - help!

I am having a major problem with file transfers - they are ending early when the bandwidth tops-out.

Smaller files transfer just fine, but large files (12Mb+) can 'abort' the transfer after maybe 35%-60% complete. I'm sending large MP3 files from my website www.TheDoctorDementoShow.com but the users are pretty upset because the files are incomplete.

I assume tis has something to do with headers or starting/stopping as the bandwidth tops-out, but I really don;t know for sure.

Is there a way I can find out why this is happening, or build in some logic to make sure the transfers don't end early?

I'm using the following code:

<?php
function send_file($path , $name) {
set_magic_quote s_runtime(0);
if (!is_file($path )) return(FALSE);
$len = filesize($path) ;
$ctype="audio/mpeg";
header("Cache-control: public");
header("Pragma: public");
header("Content-Type: $ctype");
header("Accept-Ranges: bytes");
$header="Conten t-Disposition: attachment; filename=\"" . $name . "\";";
header($header) ;
header("Accept-Ranges: bytes");
header("Content-Length: " . $len);

if ($file = fopen($path, 'rb')) {
while(!feof($fi le)) {
set_time_limit( 0);
$buf = fread($file, 1024*256);
set_time_limit( 0);
echo($buf);
set_time_limit( 0);
flush();
}
fclose($file);
}
return(1);
}
?>

Wayne R.

Jul 17 '05 #1
5 3616
<wa***@gpnservi ces.com> wrote in
news:b7******** ************@gi ganews.com:
I am having a major problem with file transfers - they are ending
early when the bandwidth tops-out.

Smaller files transfer just fine, but large files (12Mb+) can 'abort'
the transfer after maybe 35%-60% complete. I'm sending large MP3 files
from my website www.TheDoctorDementoShow.com but the users are pretty
upset because the files are incomplete.

I assume tis has something to do with headers or starting/stopping as
the bandwidth tops-out, but I really don;t know for sure.

Is there a way I can find out why this is happening, or build in some
logic to make sure the transfers don't end early?


The aborted downloads may be happening due to a script timeout. Try
adding this line at the very top of your script:

set_time_limit( 0);

This may solve the problem, or it may not. Your web host may have PHP
configured so that you can't override the script timeout.

hth

--

Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #2

<wa***@gpnservi ces.com> wrote in message news:b7******** ************@gi ganews.com...
I am having a major problem with file transfers - they are ending early when the bandwidth tops-out.

Smaller files transfer just fine, but large files (12Mb+) can 'abort' the transfer after maybe 35%-60% complete. I'm sending large MP3 files from my website www.TheDoctorDementoShow.com but the users are pretty upset because the files are incomplete.
I assume tis has something to do with headers or starting/stopping as the bandwidth tops-out, but I really don;t know for sure.

Is there a way I can find out why this is happening, or build in some logic to make sure the transfers don't end early?

I'm using the following code:

<?php
function send_file($path , $name) {
set_magic_quote s_runtime(0);
if (!is_file($path )) return(FALSE);
$len = filesize($path) ;
$ctype="audio/mpeg";
header("Cache-control: public");
header("Pragma: public");
header("Content-Type: $ctype");
header("Accept-Ranges: bytes");
$header="Conten t-Disposition: attachment; filename=\"" . $name . "\";";
header($header) ;
header("Accept-Ranges: bytes");
header("Content-Length: " . $len);
why won't you just use readfile($path) in here
and set_time_limit([seconds to set]) at the top


if ($file = fopen($path, 'rb')) {
while(!feof($fi le)) {
set_time_limit( 0);
$buf = fread($file, 1024*256);
set_time_limit( 0);
echo($buf);
set_time_limit( 0);
flush();
}
fclose($file);
}
return(1);
}
?>

Wayne R.

Jul 17 '05 #3
<wa***@gpnservi ces.com> wrote in message
news:b7******** ************@gi ganews.com...
I am having a major problem with file transfers - they are ending early when the bandwidth tops-out.
Smaller files transfer just fine, but large files (12Mb+) can 'abort' the transfer after maybe 35%-60% complete. I'm sending large MP3 files from my
website www.TheDoctorDementoShow.com but the users are pretty upset because
the files are incomplete.
I assume tis has something to do with headers or starting/stopping as the bandwidth tops-out, but I really don;t know for sure.
Is there a way I can find out why this is happening, or build in some

logic to make sure the transfers don't end early?

My suggestion is to leave it to Apache to serve the files. Apache can do it
much more efficiently and it also lets users resume interrupted downloads.

To control access to these files from PHP, use an Apache rewrite map.
Jul 17 '05 #4
I'm not sure I follow what you’re referring to.

Let me explain why I'm using PHP as opposed to a direct link on the
page:

1.) I want to record the number of files and bytes each user’s
transfers

2.) I don't want them to know the file locations so that can just URL
into the files (they might do this to avoid #1 above or to direct-link
to my files on their web pages). A session validates that they are
logged-in and not a 'snatcher'.

It appears that a rewrite map can take care of #2, but I don't see how
to initiate the transfer using PHP once I've validated the session and
recorded the # of bytes.

Basically, the user clicks on a link that runs a PHP script with the
database record number. The script looks up the number, gets the
filename and folder, records the bytes and sends the file.

I'd love to allow resume! Also, I'd like to know if Apache will
compensate for bad packets (back up to the last good packet in the
file and then resume forward again). After all, bad packets do happen.

Wayne

On Wed, 9 Feb 2005 20:55:26 -0500, "Chung Leong"
<ch***********@ hotmail.com> wrote:
<wa***@gpnserv ices.com> wrote in message
news:b7******* *************@g iganews.com...
I am having a major problem with file transfers - they are ending early

when the bandwidth tops-out.

Smaller files transfer just fine, but large files (12Mb+) can 'abort' the

transfer after maybe 35%-60% complete. I'm sending large MP3 files from my
website www.TheDoctorDementoShow.com but the users are pretty upset because
the files are incomplete.

I assume tis has something to do with headers or starting/stopping as the

bandwidth tops-out, but I really don;t know for sure.

Is there a way I can find out why this is happening, or build in some

logic to make sure the transfers don't end early?

My suggestion is to leave it to Apache to serve the files. Apache can do it
much more efficiently and it also lets users resume interrupted downloads.

To control access to these files from PHP, use an Apache rewrite map.


Jul 17 '05 #5
"Wayne R." <au*******@yaho o.com> wrote in message
news:q7******** *************** *********@4ax.c om...
I'm not sure I follow what you're referring to.

Let me explain why I'm using PHP as opposed to a direct link on the
page:

1.) I want to record the number of files and bytes each user's
transfers

2.) I don't want them to know the file locations so that can just URL
into the files (they might do this to avoid #1 above or to direct-link
to my files on their web pages). A session validates that they are
logged-in and not a 'snatcher'.

It appears that a rewrite map can take care of #2, but I don't see how
to initiate the transfer using PHP once I've validated the session and
recorded the # of bytes.

Basically, the user clicks on a link that runs a PHP script with the
database record number. The script looks up the number, gets the
filename and folder, records the bytes and sends the file.

I'd love to allow resume! Also, I'd like to know if Apache will
compensate for bad packets (back up to the last good packet in the
file and then resume forward again). After all, bad packets do happen.


When the user logs in, you write his/her session id to the rewrite map.
Something like this:

#this is a rewrite map write
2b712a3be45a352 47d89a1edab5c92 e0 dingo
2b712a3be45a352 47d8921edab5c9e 01 dingo

Then you use one RewriteCond to capture the session id from the cookie, and
another to perform a hash lookup from the map file using the session id a
key:

RewriteMap access txt:C:/access.map

RewriteCond %{HTTP_COOKIE} PHPSESSID=(\w+)
RewriteCond ${access:%1} dingo
RewriteRule /bogus/(.*) C:/Restricted/$1

The rewrite rule is only performed if the session id was written to the map
file earlier. Now, "bogus" isn't actually a folder in the document root.
When someone not authorized to download the file access the link, he/she
gets a 404 file not found error. For authorized users, the URL gets
rewritten to an actual location and the download can be downloaded.

Another way to implement this is to invert the logic, rewrite the URL so it
goes to "You have no access, haha!" page when the session id isn't present
in the map file:

RewriteCond %{HTTP_COOKIE} !PHPSESSID=(\w+ ) [OR]
RewriteCond ${access:%1} !dingo
RewriteRule /mp3/.* /noaccess.html

The easy way to record the number of bytes is to link to a PHP file, which
records the size of the file being downloaded, and have it redirect to the
URL of the MP3 file. Here, we're assuming the download will run to
completion.

The harder, more accurate way is to capture the download info using a piped
log. Have Apache pipe the log entries for MP3 file access to a CLI PHP
script. Get the session id from the cookie to figure out who the downloader
is, then save the info in the database.

All this is complete voodoo, of course. It's worth pursuing though because
it will make your site much more scalable. Another benefit is HTTP partial
retrieval, used for resuming aborted download. Some media players also use
partial retrieval to allow users to seek ahead during playback.
--
Project Wapache - http://wapache.sourceforge.net
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4046
by: Chris Mosser | last post by:
I'm looking for an applet that allows for multiple file uploads. I found jupload and am considering using that, but I might have a couple issues. I need to build a web app for a print shop, that allows their clients to upload their finished files. Problem is, these files are likely to be upto 10 megs each with the possibility of having...
7
12836
by: Limey Drink | last post by:
Hi all, Firstly :-) , is there any where I can search through archived newsgroup posts so I am not cluttering up the newsgroup with repeated queries ? And secondly :-), I know this has probably been discussed before but. I am wanting to do some scripting to automate a few administration tasks, one of the first tasks is automating FTP...
11
3602
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own rules when it comes to file paths. A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle...
8
7446
by: Imran | last post by:
hello all, I have to parse a text file and get some value in that. text file content is as follows. ####TEXT FILE CONTENT STARTS HERE ##### /start first 0x1234 AC /end
4
2115
by: Stuk | last post by:
Hi, im false beginner in C so that`s why im writting here :). I have to write a Text Reformater, which should read data from text file every Verse. In text file may appear special directives (for example .xx n where n is a variable). Every directive, cause something else (set marigin, space between verses, lenght of page, header, etc.) I...
2
2692
by: =?Utf-8?B?SkRhdmlkZQ==?= | last post by:
Hello again! :( I'm trying to implement asynchronous DnD (and Copy/Paste) in a custom NSE: despite the lack of documentation, I found that i need my DataObject implement the optional interface IAsyncOperation. I want to always use asynchronous operations, so I added the following lines to my DataObject class (I use ATL): class...
4
6499
by: bdan44 | last post by:
i am a total n00b at perl. i just started learning yesterday. I wanted to make a script to rename extentions. this is what i've come up with. i can't figure out why it doesn't work. any help would be appreciated. #!/usr/bin/perl print "What ending would you like to change?"; $ending = <STDIN>; chomp($ending); print "What would you...
10
10595
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an example to follow for using a tcp socket to transfer files between client/server, server/client. Both server and client are my program so I'm not...
1
5577
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to execute it using tomcat server5.5. the code is as follows. if you have any other coding regarding this, please send me.it's urgent. import...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.