Welcome to WebmasterWorld Guest from 54.196.145.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Strange problem: session and readfile

session_start will create another thread?

     
10:25 am on Aug 3, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 19, 2003
posts:324
votes: 0


I have a script which sends file to end user:

<?
...
header('length, type...')
readfile('file-to-download.dat');

//the following script should be executed after the whole file downloaded completely.
mail('my@email.com', 'Download completed', 'body', 'from: my@email.com');
?>

It works without any problem. The readfile function shows the "File download" dialog of IE and I won't receive email until IE downloaded the whole file.

However, I found that I need to use session in this script, so I added session_start() at the beginning of this it:

<?
session_start()
...
?>

And suddenly, as long as I execute this script, without finishing the download, I can receive the email message immediately. Why this happened? Is there a way to solve this problem?

11:58 am on Aug 3, 2006 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4397
votes: 2


It could be that your PHP.INI does not allow for header not to be set at the your page very top,
as such the order of actions could be changed.
12:31 pm on Aug 3, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 19, 2003
posts:324
votes: 0


So which parameter of php.ini should I look at? I could not move the session_start() to lines under readfile().
12:55 pm on Aug 3, 2006 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts:4397
votes: 2


Try turning output buffering on

output_buffering = On
so there in no " ; " at the beginning of the line

This allows for sending headers from any position in your script
It is done at the cost of a very slightly slow-down of the exec.
However you should not be scared about it unless your script is a huge one with a heavy load of PHP calls.

<edit>
Don't forget to restart Apache
</edit>

2:41 pm on Aug 3, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 19, 2003
posts:324
votes: 0


I'm trembling, abandon seesion in this script is a better solution ;-)