简体   繁体   English

认真加速PHP?

[英]Seriously speeding up PHP?

I've been writing PHP for years, and have used every framework under the sun, but one thing has always bugged me... and that's that the whole bloody thing has to be interpreted and executed every time someone tells my server they want the page served. 我已经写PHP多年了,并且在阳光下使用了每个框架,但是一件事一直困扰着我……那就是,每当有人告诉我的服务器他们想要的东西时,就必须解释和执行整个流血的事情。页面已投放。

I've experimented with caching, FastCGI, the Zend Job Queue (and symfony plug-ins that do similar - as well as my own DB-based solutions that implement the System_Daemon class to run background processes) and I've managed to make my apps fairly quick using all that stuff... but I can't get over the mental block that my settings files, system/environment check functions, and all the stuff that should only really be loaded ONCE... loads every darn time someone hits my page. 我已经尝试过缓存,FastCGI,Zend Job Queue(以及类似的symfony插件-以及我自己的基于DB的解决方案,这些解决方案实现了System_Daemon类以运行后台进程),并且设法使应用程序使用所有这些东西的速度都相当快...但是我无法克服我的设置文件,系统/环境检查功能以及所有仅应一次加载的所有东西的心理障碍...每当某人被加载时,点击我的页面。

So, my ramble leads to the following Q-- 因此,我的漫步导致以下问题-

Is there some method/technique for loading certain aspects of PHP into RAM so that when that page is requested, all my settings.yml files, system checks, framework files, cached pages etc can be loaded directly from memory without ever even touching the HD... or needing to go through the same loading mechanism 50,000 times per day to init the program? 是否有某种方法/技术可以将PHP的某些方面加载到RAM中,以便在请求该页面时,我的所有settings.yml文件,系统检查,框架文件,缓存的页面等都可以直接从内存中加载,甚至无需接触HD ...还是每天需要通过相同的加载机制50,000次来启动程序?

If there's nothing in PHP... are there any other 'web' languages that can be compiled in this way, to allow for true init-once apps? 如果PHP中没有任何内容...是否可以通过这种方式编译其他“网络”语言,以允许真正的一次启动应用程序?

I think you should give memcached a try, if you're talking about caching data. 如果您正在谈论缓存数据,我认为您应该尝试一下memcached I think PHP is fairly proficient in caching compiled php-pages if you use stuff like mod_php in apache (which doesn't die in between requests). 我认为,如果您在apache中使用mod_php之类的东西(不会在两次请求之间死亡),PHP会相当熟练地缓存已编译的php页面。

Take a look on APC (Alternative PHP Cache) , it keeps a cache of compiled files (PHP Opcode) and also lets you store random variables on memory with apc_fetch, apc_store. 看一下APC(备用PHP缓存) ,它保留了已编译文件的缓存(PHP Opcode),还允许您使用apc_fetch,apc_store将随机变量存储在内存中。

The instalation is very simple and it really gives a boost on performance. 安装非常简单,确实可以提高性能。

Create a full page cache on the ram disk and make your web server serve the page from there. 在ram磁盘上创建一个完整的页面缓存,并使您的Web服务器从那里提供页面。 This is a method that wordpress supercache plugin uses and it works great if your web site is suitable for full page caching. 这是wordpress超级缓存插件使用的一种方法,如果您的网站适合全页缓存,则该方法效果很好。 This whay you are not even invoking the PHP interpreter. 这样,您甚至都没有调用PHP解释器。

For users that are logged in (have an open session) you can create a rewrite condition that will redirect their request to the PHP engine. 对于已登录(具有打开的会话)的用户,您可以创建一个重写条件,该条件会将他们的请求重定向到PHP引擎。

Also, always use an opcode cache like APC and use it for caching config files (memcache is also fine). 此外,请始终使用操作码缓存(如APC)并将其用于缓存配置文件(内存缓存也可以)。

If you are asking for a JVM/Tomcat like application server, then the answer is likely no. 如果您要使用类似JVM / Tomcat的应用程序服务器,那么答案可能是“否”。 To my knowledge nothing (usable) like this exists for PHP. 据我所知,PHP没有这样的(可用)东西。 PHP uses a shared-nothing architecture, so it is by design everything is setup on all requests. PHP使用无共享架构,因此在设计上,所有内容都针对所有请求进行了设置。 But actually, this makes PHP scale pretty well. 但是实际上,这使PHP可以很好地扩展。

As for speeding up your apps, try to use memcached and a code accelerator . 至于加速应用程序,请尝试使用memcached代码加速器 Maybe look into Zend Server to get a complete package. 也许看看Zend Server以获得完整的软件包。

Regarding your last question, I believe at least most of the Python and Ruby web frameworks work like that. 关于您的最后一个问题,我相信至少大多数Python和Ruby Web框架都是这样工作的。

Ruby web applications are nowadays built so that the app is only initialized once per server process. 如今,Ruby Web应用程序已构建,因此该应用程序在每个服务器进程中仅初始化一次。 When requests come in, the server (Apache, for example) passes them to the web application (over Rack interface) which is running on the background. 当请求进入时,服务器(例如Apache)将它们传递到在后台运行的Web应用程序(通过Rack接口)。

This is how web frameworks based on Rack work. 这就是基于Rack的 Web框架的工作方式。 Older versions of Ruby on Rails were similar, although they used a different interface to talk to the web server. Ruby on Rails的旧版本相似,尽管它们使用不同的界面与Web服务器通信。

I'd keep an eye on the Facebook Engineering ppage ( http://www.facebook.com/notes.php?id=9445547199 ), every now and then they come up with posts about how they keep things fast/optimize/scale. 我会密切注意Facebook Engineering ppage( http://www.facebook.com/notes.php?id=9445547199 ),然后他们不时提出有关如何快速/优化/扩展内容的帖子。 。 I think they're use of php is super impressive. 我认为他们对php的使用非常令人印象深刻。

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

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