So tonight I ran into an interesting issue this evening in configuring PECL memcache to run on my Macintosh. To give you a bit of background, I use the built-in copy of Apache, but with PHP (current 5.2.8) compiled from source since the version in Leopard is old and I needed some things that it didn’t provice. After that was installed with no problems, I went to the ext/memcache-3.0.4 directory to compile memcache as so: ...
The bug in our code (and the above link) is that there is a race gap between the memcache::get() and memcache::set(). This is perfectly fine if all you want to do is prevent a stampede since only a few, even on a slow system like PHP, would be in the winners circle of that race. This sort of thing is really bad in the above case.
So what is the solution? The solution is to use a memcache command that is more atomic. The one that fits the bill is memcache_add() which, if a key is already added returns a failure condition.
pcode caches save energy, expenses, improve overall user experience on web sites, and it's often one of the simplest optimizations to implement. This article will explain the basics of installing, configuring, and tuning an opcode cache for PHP, the Alternative PHP Cache (APC).
PHP programmers don't really understand PHP.
They know how to use PHP - but they hardly know how it works, mainly because it Just Works most of the time. But such wilful ignorance (otherwise known as abstraction) often runs them aground on some issues when their code meets the stupidity that is APC. Bear with me while I explain how something very simple about PHP - how includes work.
Every single include that you do in PHP is evaluated at runtime. This is necessary so that you could technically write an include inside an if condition or a while loop and have it behave as you would expect. But executing PHP in Zend is actually a two step process - compile *and* execute, of which APC gets to handle only the first.
Every time a request hits your server, PHP has to do a lot of processing, all of your code has to be compiled & executed for every single visit. Even though the outcome of all this processing is often identical for both visitor 21600 and 21601. So why not save the flat HTML generated for visitor 21600, and serve that to 21601 as well? This will relieve resources of your web server and database server because less PHP often means less queries.
“MemCached” is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
In this article I will try to give a view of what is the custom caching with php, why and how we can use it.
In the modern days, most of the sites are database driven. That means that your site is actually an application which retrieves data from a DBMS ( database managment system, eg MySQL) , parses the data and shows the result to the user. Most of these data are usually don't change frequently or don't change at all, and the reason that we use the database is that we can easilly update the site and the content.
A problem that this process creates is the server overhead. Every time we execute a query in the database, the instance of our script will call the DBMS, and then the DBMS will send the results of the query. This is time consuming, and especcially for sites with heavy traffic is a real big problem.
PHP generated content is by its nature dynamic. However, in most cases the content displayed is static or rarely changing.
By caching static components of the page or even entire pages it is possible to reduce the processing time involved in generating a page.
Over the past day I've been going through a few web applications and preparing them in the event they get digged or slashdotted. One of my primary goals was to cache as much data to disk, rather than hitting the database for it each time. Now, most of the web applications I have written myself, so I didn't have the luxury of some type of pre-made mod or plug-in. In one case, this textpattern installation, I did have that luxury.
For the textpattern installation, I just used the wonderful asy-jpcache plug-in. It does full page caching, which is what I was looking for in this instance. It will expire the cache when an article is added, edited, or deleted. It also expires the page cache if a comment is posted. Enabling page level caching in this textpattern installation has made us able to serve roughly 20 times the number of pages before reaching a critical load. Quite impressive!
When your building fancy AJAX websites one thing that tends to happen is you end up loading amounts of JavaScript and CSS on your pages. And while browsers are smart and do a lot of client side caching you can’t get rid of that weight on your first page load.
For example on my blog I have about 60K of JavaScript and 10K of CSS. Now this isn’t horrible but when you figure images and 90K of HTML it doesn’t take long to get to my 200K total page weight.
There are a lot of various approaches for cutting down the size of JavaScript and CSS. Some of the common ones are removing whitespace and comments for JS and CSS, or using scripts which use alternate smaller syntaxes. There are a couple problems with this approach first it just doesn’t save as much space as I’d like, you can cut 60K of JavaScript down to 30K but not 10K. Second it makes debugging horrible, every JavaScript or CSS error comes from line 1 or the file.
There is a better approach and it comes from a technology in our browsers called Content Encoding. With the right headers we can send gzip’d content to the browser and it will automatically uncompress it. All modern browsers support this so its a huge win.








