简体   繁体   English

在Apache中使用mod_rewrite

[英]mod_rewrite in apache

I have image hosting. 我有图像托管。 All image requests redirect to a PHP script with mod_rewrite. 所有图像请求都使用mod_rewrite重定向到PHP脚本。 PHP script uses function fread() and displays picture from another file. PHP脚本使用函数fread()并显示另一个文件中的图片。 I want to know, does this use a lot of processor time or not? 我想知道,这是否占用大量处理器时间?

It depends on how much you think "a lot of processor time" is, but from what you're describing, the processing time required by mod_rewrite and PHP is trivial compared to the I/O time to read the image from disk and send it over the network. 它取决于您认为“大量处理器时间”的多少,但是根据您的描述,与从磁盘读取并发送图像的I / O时间相比,mod_rewrite和PHP所需的处理时间微不足道。通过网络。

If you're concerned about speed, caching the images in memory will probably have the most benefit. 如果您担心速度,则将图像缓存在内存中可能会获得最大的好处。

Yes, this is putting considerable strain on the web server, because the PHP interpreter has to be initialized for every small resource request, and passes through the data. 是的,这给Web服务器带来了很大的压力,因为必须为每个小的资源请求初始化PHP解释器,然后传递数据。 The consensus is that this is not a good thing to do on a high-traffic website. 共识是,在高流量的网站上这样做不是一件好事。

Why are you doing this, are you resizing images? 为什么要这样做,要调整图像大小吗?

在达到CPU限制之前,您将用完内存:-)读/写文件不是CPU密集型任务,但是为此创建的每个apache进程最多会占用50 MB的RAM。

If you want to send images fast and secure, you should look into X-SendFile - this allows your php scripts to tell your Webserver to send files not directly accessible by url using something like header('X-SendFile: /path/to/the/file'); 如果您想快速安全地发送图像,则应查看X-SendFile-这使您的php脚本可以告诉您的Web服务器发送文件头不能使用header('X-SendFile: /path/to/the/file');

For apache there is mod_xsendfile ( http://tn123.ath.cx/mod_xsendfile/ ) though labeled beta, it has proven to be very stable in production, and the its sourcecode is rather small and can be audited easily. 对于Apache,虽然有标记为beta的文件,但仍然有mod_xsendfile( http://tn123.ath.cx/mod_xsendfile/ ),它在生产中非常稳定,其源代码非常小,可以轻松进行审核。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM