Store
Community Documentation

v3 Knowledgebase

Improving the scalability and performance of phpFox

One of the most common questions nowadays is "how to make my site faster?".

Added to this question, a corollary: "what if I reach a big number of users? Will my site crash or will it be unusable?"

Well, answering these questions, we want to give you some tips about how to scale your site to have a big number of users; and if you already have them, then on how to improve the performance of your site.

Let's focus on the scalability first. There is a very known proverb that says "two heads are better than one". In our case, that is correct! If you are planning to have or if you already have a large amount of users, you can make the site managed by two systems instead of only one. How? With these three basic options:

1. Using database slave servers and replication, to distribute the files load and the database load in various servers.
2. Cache servers like Memcached, used to cache the most consumed database queries in RAM to reduce the number of queries performed to the database server.
3. Content Delivery Networks (CDN) to save bandwidth and disk space.

By default phpFox offers the possibility to use those three features, you just have to configure the below steps:

1. To enable replication: http://www.phpfox.com/kb/article/95/how-to-enable-mysql-replication/
2. To enable Memcached: http://www.phpfox.com/kb/article/94/how-to-enable-memcached/
3. To enable Amazon S3 CDN: http://www.phpfox.com/kb/article/96/how-to-enable-amazon-s3-support/

In case you can't opt for a replication server for the database, or if you want to improve more on the performance, there is another option you can try. It is called "table partitioning". Partitioning is a logical division of a table, that divides into independent parts, while at the same time still being one. Then it's faster and it's easier to search for in a part of a table instead of an entire table."

The four main reasons to use this feature are:

1. To make single inserts and selects faster
2. To make range selects faster
3. To help split the data across different paths
4. To store historical data efficiently

When to use partitions?
  • if you have large tables
  • if you know that you will always query for the partitioning column
  • if you have historical tables that you want to purge quickly
  • if your indexes are larger than the available RAM


The instructions for the table partitioning can be found here:
  • http://dev.mysql.com/doc/refman/5.1/en/partitioning.html
  • http://dev.mysql.com/doc/refman/5.1/en/partitioning-types.html


United to replication and partitioning, you can use the MySQL storage engine called "InnoDB" to improve the scalability (and implicitly, the performance).

PhpFox by default uses the "MyISAM" storage engine, as it is faster for common sites without large amounts of users. Besides, it is the default storage engine of MySQL and almost all MySQL servers supports it.

The main difference between MyISAM and InnoDB is the ACID-compliant (Atomicity, Consistency, Isolation, Durability) transaction features present in InnoDB. This allows InnoDB to have locks at rows and columns level, which is better on large tables than the locks at table level carried on by MyISAM.

Therefore, InnoDB could increase the performance of your site with large tables. Just keep in mind InnoDB offers better results on MySQL 5.5 or up.

Of course, you are free to use replication and partitioning with InnoDB. The combination can produce a huge improvement in your site. They're not exclusive.

Finally, and in case you want to keep your server extremely fast no matter if you have to sacrifice a little bit of data, you can set up cron jobs to clean up the database tables that grow very fast and whose content is not important enough to be forced to save it (like the update feeds, the IM chat and the shoutbox).

Remember, big amount of entries in database tables can generate slow queries if they are not partitioned and/or properly indexed.

As a side note, but related to the IM and the shoutbox, keep in mind that the default phpFox's IM chat (and shoutbox) use a very greedy resource consumption technology called "long pooling", in order to keep the shouts and chat updated. The problem with this technology, is that it uses the server to keep the shouts and the chat updated.

Therefore, replacing the default IM and shoutbox with a peer-to-peer IM chat and a peer-to-peer shoutbox can increase the performance very much, because the peer-to-peer technology avoids the use of the server to keep the shouts and chat updated. How? By keeping a direct connection among the users involved, instead of using the server as a centralized place to update.

The mix of all these tips have shown an increase of performance in all the tests performed.