Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making use of C++ to speed up PHP

Tags:

c++

php

I saw this post on Sitepoint quoting a statement by Rasmus Lerdorf which goes (according to Sitepoint) as follows:

How can you make PHP fast? Well, you can’t" was his quick answer. PHP is simply not fast enough to scale to Yahoo levels. PHP was never meant for those sorts of tasks. "Any script based language is simply not fast enough". To get the speed that is necessary for truly massive web systems you have to use compiled C++ extensions to get true, scaleable architecture. That is what Yahoo does and so do many other PHP heavyweights.

Intrigued by the statement (not to mention the fact that up to now, all I was doing in PHP was small database-based applications), I was wondering how I could "use compiled C++ extensions" with PHP.

Any ideas or resources?

like image 309
yretuta Avatar asked Apr 10 '10 08:04

yretuta


People also ask

Why is PHP so slow?

So why is PHP slow in comparison with some other languages? PHP is a dynamic, interpreted language. This means that it is not compiled to machine language but rather read at runtime. PHP also has a share-nothing architecture, so on every request it interprets everything from fresh.

What is PHP optimization code?

Another way for PHP performance optimization is minifying JS and CSS code; this will make it unreadable by humans, but when we are talking about web applications that are in production, readability of code is not a priority. Also minifying your code reduces the size of a file, which improves load times.


2 Answers

Don't even bother. PHP is slow... You may create a mixture of C++ and PHP but you'll need to do lots of profiling to understand what is slow. And this is mostly... PHP.

See following:

  • C++ vs PHP Benchmarks for real web software
  • Is Data Base the Bottle Neck of Web Service? (not really... or why wikimedia has so many servers)
  • Slashdot article about Facebook (or how many resources PHP wastes)

Just write in C++ in first place. It is as simple as writing in PHP with modern C++ web framework and good knowledge in C++.

Where to start:

  • CppCMS - scalable MVC framework oriented for performance.
  • Wt - framework that mimics Qt for web (not sure how it scales well).
like image 180
Artyom Avatar answered Sep 23 '22 23:09

Artyom


Slow is subjective term. Facebook (the biggest site online) is built on PHP and I never heard them complain. In the contrary in their pursuit of speed the developed and recently released HipHop If you are going for ultrafast PHP this is where you should focus. C++ for web is kind of impractical because it needs to be compiled and it will slowdown the development process.

Because: Why are so many web languages interpreted rather than compiled?

http://www.bitsandbuzz.com/article/compiled-web-vs-interpreted-web/

like image 40
Ivo Sabev Avatar answered Sep 22 '22 23:09

Ivo Sabev