How to make PHP apps scale
The most popular language for Web apps, PHP tends to buckle under heavy loads -- unless you opt for cloud scaling and a NoSQL back end
Infoworld - The power of PHP and an RDBMS is the ability to nail the major features of an application with cheaply paid developers in a record amount of time. Unfortunately, the default runtime environment used by PHP is simply an unscalable mess.
A lot of the folks I've worked with do not care about maintainability; their PHP applications are throwaway, but heavily loaded and highly concurrent. For example, I worked with a company that developed a PHP marketing application with an Oracle back end, where you bought its products and could exchange your "points" for features of an online game. It worked great -- until it reached a few million users.
[ See InfoWorld's review of fabulous PHP frameworks and MongoDB's flexible, scalable take on NoSQL. | Follow the latest issues in software development with InfoWorld's Developer World newsletter. ]
The truth is that if you have enough servers and enough database servers, you don't have contention. But with a PHP Web app on top, an RDBMS like Oracle just can't be scaled cost-effectively to deliver both good read and write performance.
As it turns out, there's a modern solution to the problem: the cloud plus NoSQL. Cloud infrastructure gives us the ability to spin up enough servers, and a NoSQL database enables us to shard our data effectively. But first, let's examine why PHP's runtime environment is such dog to begin with.
Why PHP's runtime environment sucksThe most common runtime for PHP is the Apache Web Server in prefork mode, which means that the Web server runs a series of separate subprocesses to support concurrent requests. When you combine this concurrency characteristic with the use of a traditional relational database like MySQL, PostgreSQL, or Oracle, this choice implies unpooled database connections because database connection pooling requires a shared memory space.
Native threads, on the other hand, have a shared memory space as part of their master process. Subprocesses do not have a shared memory space unless you use a specific operating system area called "shared memory." This isn't as fast as being able to pass memory by reference -- besides, the Apache Web Server's "prefork" module doesn't support the use of shared memory for this purpose anyhow. It is sometimes possible to run PHP with native threads, aka worker mode, but this is heavily dependent on the modules you use and whether those modules are "thread safe."
The PHP concurrency model has a major impact on vertical scalability when using a traditional RDBMS. While it's possible to open thousands of unshared concurrent connections to MySQL or Oracle, this has a fairly negative impact on the number of concurrent requests. A typical PHP application -- indeed, any Web application -- consists of logic along these lines:
- Google I/O 2013's Coolest Products and Services
- 10 Star Trek Technologies That are Almost Here
- 19 Generations of Computer Programmers
- 25 Must-Have Technologies for SMBs
- A walking tour: 33 questions to ask about your company's security
- 15 social media scams
- The 7 elements of a successful security awareness program
- IT Certification Study Tips
- Register for this Computerworld Insider Study Tip guide and gain access to hundreds of premium content articles, cheat sheets, product reviews and more.
- Intelligent Systems: A Prescription for Health Care Transformation Facing an onslaught of regulatory changes and market pressures, health care providers are grappling with how to transform existing services as part of...
- Agile Computing: The Path to Strategic Agility Financial institutions globally are facing increasing regulatory requirements while operating in a more competitive environment. Learn how to leverage technology to transform your...
- Time Savings and Ease of Deployment Comparison Study - Database Appliance vs Microsoft SQL Server As the amount and importance of corporate data grows, companies of all sizes are finding that they increasingly need to deploy high-availability database...
- Harness IT -- An Introduction to Business Intelligence Solutions Learn the key selection criteria required to provide your organization with the capability to address structured data, unstructured data and mobile demands so...
- Oracle Database Appliance Best Practices Business users increasingly demand 24x7 availability of their data while IT departments face the challenge of ensuring maximum availability while operating with limited...
-
Oracle Database Appliance - Simplifying your High Availability Database
Date: February 29, 2012
Time: 1:00 PM EST
Seasoned IT managers know from experience that in many cases the bulk of the cost of an...
All Databases White Papers |
Webcasts