Re: [PHP] Outputting File To The Browser Failed And Kill Apache

2009-06-07 Thread Nitsan Bin-Nun
Whenever I will delete the symlink the file will be no more accessible? If
so then what will happen if the user still downloading the file during the
deletion of it? I'm pretty sure it will cause a stop of the downloading
process at the client.

I'm also not that much sure whether this is the right solution for that.

I'm also not really sure that the apache problem is due to memory issue (I
honestly have no idea regarding it's meaning :X ).

Any further ideas will be highly appreciated!
Thank you Tom for your ideas :)

Regards,
Nitsan

On Sun, Jun 7, 2009 at 1:37 AM, Tom Worster  wrote:

> On 6/6/09 7:28 AM, "Nitsan Bin-Nun"  wrote:
>
> > The files are one directory up from the www root, because that I don't
> want
> > straight access to them, only by validation which will be done in this
> php
> > file.
> >
> > I'm not an apache expret, do you have any idea how I can run this php
> > validation file and then output the file, which is placed in one up
> > directory from the www root to the user browser??
>
> when you say "validation", do you mean that you perform certain checks on a
> given client request in php in order to decide whether or not to allow the
> client to download the file?
>
> i can only think of one thing offhand and it's not high security but it
> would make unauthorized access a lot harder. after validating the client
> request, create a temporary symlink to the file that the client wants in a
> directory under the http root using a random filename. redirect the client
> to the symlink and delete it x minutes later. the entropy of the symlink
> filename determines how hard it is to guess and its ephemeral existence
> makes it hard to discover or reuse.
>
> i don't know if apache has a way to restrict access by referrer but that
> would add an additional level of security, i.e. if apache could be
> configured to reject the request to the symlink unless the referrer points
> to the server that sent the redirect.
>
> sorry i can't be of more help. on the other hand, it's not easy to
> implement the flow control between the flie and apache and thus to the
> client's tcp connection in php so that nothing gets stuck and no buffers
> overflow. i'm not really convinced that's a function that belongs in a php
> script.
>
>
>


Re: [PHP] Outputting File To The Browser Failed And Kill Apache

2009-06-05 Thread Tom Worster
if the problem is due to flow control issues between the script and the
httpd server then perhaps changing the approach could help.

i quit using this approach of writing files to the php output buffer a
little while ago. it seemed that it was better to leave the flow control
issues entirely to apache. so i wrote the file to a specific directory on
the server and redirected the client to it, using the apache directive on
that directory:
Header set Content-Disposition attachment

you can use that directive to send whatever headers you need.


On 6/5/09 3:52 PM, "Nitsan Bin-Nun"  wrote:

> Hi List,
> 
> I'm using the following code to output a file to the browser. Each file size
> is in the range of 5-10MB, all of them are MP3.
> 
> header("Pragma: public");
>> header("Expires: 0");
>> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>> header("Cache-Control: public");
>> header("Content-Description: File Transfer");
>> header("Content-Type: {$info['mimetype']}");
>> header("Content-Disposition: attachment;
>> filename=\"{$info['filename']}\"");
>> header("Content-Transfer-Encoding: binary");
>> header("Content-Length: " . $info['size']);
>> 
>> set_time_limit(0);
>> 
>> $file =
>> @fopen($config['storage'][$config['current_storage']].$info['md5'].".".$info[
>> 'extension'],"rb");
>> if ($file) {
>> while(!feof($file)) {
>> print(fread($file, 1024*8));
>> flush();
>> if (connection_status()!=0) {
>> @fclose($file);
>> die();
>> }
>> }
>> @fclose($file);
>> }
> 
> 
> 
> I'm running this script on a VPS which has a 10MBIT connection. When I
> posted a link to this download stream php file about 50 users started
> download it, then the script stopped from sending the whole file (for
> instance, the file is 5MB, the script sends 2MB, 1MB and it continue this
> way).
> 
> In the apache log file I have seen these lines, but I have no idea what are
> their meaning:
> 
> [Fri Jun 05 22:02:28 2009] [error] (12)Cannot allocate memory: fork: Unable
>> to fork new process
>> [Fri Jun 05 22:02:38 2009] [error] (12)Cannot allocate memory: fork: Unable
>> to fork new process
>> [Fri Jun 05 22:02:48 2009] [error] (12)Cannot allocate memory: fork: Unable
>> to fork new process
>> [Fri Jun 05 22:11:35 2009] [error] (12)Cannot allocate memory: fork: Unable
>> to fork new process
>> 
> 
> 
> I have no idea what's going on. Any ideas to solve this issue will be very
> appreciated. My 12K users are suffering right now, I would really really
> appreciate any idea in the right direction :) :) :)
> 
> Thank you!



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Outputting File To The Browser Failed And Kill Apache

2009-06-05 Thread Nitsan Bin-Nun
My partner ran this command through SSH.
This is the returned value: (as root)

[r...@s1 ~]# ulimit -a
> core file size  (blocks, -c) 0
> data seg size   (kbytes, -d) unlimited
> file size   (blocks, -f) unlimited
> pending signals (-i) 397311
> max locked memory   (kbytes, -l) 32
> max memory size (kbytes, -m) unlimited
> open files  (-n) 1024
> pipe size(512 bytes, -p) 8
> POSIX message queues (bytes, -q) 819200
> stack size  (kbytes, -s) 10240
> cpu time   (seconds, -t) unlimited
> max user processes  (-u) 397311
> virtual memory  (kbytes, -v) unlimited
> file locks  (-x) unlimited
>


This is the output as the user files which runs my PHP files:

[fi...@s1 root]$ ulimit -a
> core file size  (blocks, -c) 0
> data seg size   (kbytes, -d) unlimited
> file size   (blocks, -f) unlimited
> pending signals (-i) 397311
> max locked memory   (kbytes, -l) 32
> max memory size (kbytes, -m) unlimited
> open files  (-n) 1024
> pipe size(512 bytes, -p) 8
> POSIX message queues (bytes, -q) 819200
> stack size  (kbytes, -s) 10240
> cpu time   (seconds, -t) unlimited
> max user processes  (-u) 397311
> virtual memory  (kbytes, -v) unlimited
> file locks  (-x) unlimited
>

I have no idea which of these settings can have an effect on my script, if
you have any idea that would be highly appreciated :)

Thanks!

On Fri, Jun 5, 2009 at 10:10 PM, Marc Steinert  wrote:

> Maybe your apache user is exceeding system limitations?
>
> For further detail have a look at
>
> http://www.ss64.com/bash/ulimit.html
>
> Greetings from Germany
>
> Marc
>
>
>
> Nitsan Bin-Nun wrote:
>
>> Hi List,
>>
>> I'm using the following code to output a file to the browser. Each file
>> size
>> is in the range of 5-10MB, all of them are MP3.
>>
>> header("Pragma: public");
>>
>>> header("Expires: 0");
>>> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>>> header("Cache-Control: public");
>>> header("Content-Description: File Transfer");
>>> header("Content-Type: {$info['mimetype']}");
>>> header("Content-Disposition: attachment;
>>> filename=\"{$info['filename']}\"");
>>> header("Content-Transfer-Encoding: binary");
>>> header("Content-Length: " . $info['size']);
>>>
>>> set_time_limit(0);
>>>
>>> $file =
>>>
>>> @fopen($config['storage'][$config['current_storage']].$info['md5'].".".$info['extension'],"rb");
>>> if ($file) {
>>>while(!feof($file)) {
>>>print(fread($file, 1024*8));
>>>flush();
>>>if (connection_status()!=0) {
>>>@fclose($file);
>>>die();
>>>}
>>>}
>>>@fclose($file);
>>> }
>>>
>>
>>
>>
>> I'm running this script on a VPS which has a 10MBIT connection. When I
>> posted a link to this download stream php file about 50 users started
>> download it, then the script stopped from sending the whole file (for
>> instance, the file is 5MB, the script sends 2MB, 1MB and it continue this
>> way).
>>
>> In the apache log file I have seen these lines, but I have no idea what
>> are
>> their meaning:
>>
>> [Fri Jun 05 22:02:28 2009] [error] (12)Cannot allocate memory: fork:
>> Unable
>>
>>> to fork new process
>>> [Fri Jun 05 22:02:38 2009] [error] (12)Cannot allocate memory: fork:
>>> Unable
>>> to fork new process
>>> [Fri Jun 05 22:02:48 2009] [error] (12)Cannot allocate memory: fork:
>>> Unable
>>> to fork new process
>>> [Fri Jun 05 22:11:35 2009] [error] (12)Cannot allocate memory: fork:
>>> Unable
>>> to fork new process
>>>
>>>
>>
>> I have no idea what's going on. Any ideas to solve this issue will be very
>> appreciated. My 12K users are suffering right now, I would really really
>> appreciate any idea in the right direction :) :) :)
>>
>> Thank you!
>>
>>
>
> --
> Synchronize and share your files over the web for free
> http://bithub.net/
>
> My Twitter feed
> http://twitter.com/MarcSteinert
>
>
>
>
>


[PHP] Outputting File To The Browser Failed And Kill Apache

2009-06-05 Thread Nitsan Bin-Nun
Hi List,

I'm using the following code to output a file to the browser. Each file size
is in the range of 5-10MB, all of them are MP3.

header("Pragma: public");
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Cache-Control: public");
> header("Content-Description: File Transfer");
> header("Content-Type: {$info['mimetype']}");
> header("Content-Disposition: attachment;
> filename=\"{$info['filename']}\"");
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: " . $info['size']);
>
> set_time_limit(0);
>
> $file =
> @fopen($config['storage'][$config['current_storage']].$info['md5'].".".$info['extension'],"rb");
> if ($file) {
> while(!feof($file)) {
> print(fread($file, 1024*8));
> flush();
> if (connection_status()!=0) {
> @fclose($file);
> die();
> }
> }
> @fclose($file);
> }



I'm running this script on a VPS which has a 10MBIT connection. When I
posted a link to this download stream php file about 50 users started
download it, then the script stopped from sending the whole file (for
instance, the file is 5MB, the script sends 2MB, 1MB and it continue this
way).

In the apache log file I have seen these lines, but I have no idea what are
their meaning:

[Fri Jun 05 22:02:28 2009] [error] (12)Cannot allocate memory: fork: Unable
> to fork new process
> [Fri Jun 05 22:02:38 2009] [error] (12)Cannot allocate memory: fork: Unable
> to fork new process
> [Fri Jun 05 22:02:48 2009] [error] (12)Cannot allocate memory: fork: Unable
> to fork new process
> [Fri Jun 05 22:11:35 2009] [error] (12)Cannot allocate memory: fork: Unable
> to fork new process
>


I have no idea what's going on. Any ideas to solve this issue will be very
appreciated. My 12K users are suffering right now, I would really really
appreciate any idea in the right direction :) :) :)

Thank you!