17

Are there alternatives to PHP that perform faster and have somewhat the same feature set (like support for common RDBMS, Curl, Regex, etc)?

What about coding websites in C? How does that work out? Is that platform independent and works on each server?

4
  • 7
    Perhaps you should indicate what problems you're having (if any) with PHP Commented Jan 5, 2010 at 17:12
  • 1
    Usually the bottleneck is in waiting for the database. Profile your app/site too see what's holding it up. Commented Jan 5, 2010 at 17:16
  • You should indicate what problems you're having with PHP. And look at what language agnostic techniques are used to improve web app performance - developer.yahoo.com/performance Commented Jan 5, 2010 at 22:23
  • This blog post might be useful: hackr.io/blog/top-10-alternatives-to-php-in-2018 Commented Dec 4, 2018 at 5:51

7 Answers 7

18

Your question is broad.

  • PHP can be made fast and scalable (Flickr, Facebook and more sites run PHP)

  • Somewhat similar in purpose are webframeworks like Ruby on Rails, Django, Lift, ... (these can scale, too, see e.g. Twitter)

  • A short intro on CGI in C: http://www.cs.tut.fi/~jkorpela/forms/cgic.html

Sign up to request clarification or add additional context in comments.

1 Comment

Very minor correction: applications build in PHP can be made fast, this is true - but the language itself, by nature, cannot be made "fast", or at least not in the sense that system languages (C, C++, Go, etc.) are fast. The language itself relies on run-times written in a system language, and/or external services (DBMS, etc.) also (for the most part) written in a system language, for anything performance-critical.
9

If you like Javascript you can use it on the server-side with Node.js

Comments

8

Perl (CGI)

Python

RoR (Ruby On Rails)

ASP (Not the best option)

Pretty sure if your going to code a website in C your gonna be coding your own webserver too so I'd stay away from that.

RoR would be a good option. But it just depends on your personal preference. I tend to stick with php since I know how to do pretty much everything in PHP.

Comments

6

"Are there alternatives to PHP" - Yes

"...that perform faster..." - Yes

"...the same feature set..." - No - that would make PHP redundant.

You're asking a very broad question. There are lots of languages out there which support all sorts of DBMS, PCRE and other stuff too.

"What about coding websites in C? How does that work out? Is that platform independent and works on each server?"

  • No it's not platform independent.

Its rather difficult to point you in a specific direction based on such a broad ranging question.

You might want to read this:

http://benchmarksgame.alioth.debian.org/

But note that most of the cost of software lies in development - hardware is cheap - so being able to implement something in half the lines of code will be massively more beneficial for most people than doubling the performance.

There are also less obvious constraints and/or advantages in usuing specific languages - e.g.

http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html

C.

4 Comments

Urk, I hate that article. "7 reasons I switch back to PHP" is constantly presented as some kind of attack on Rails, when it's not - it's a demonstration of the author's ignorance. His first words are "I spent two years trying to make Rails do something it wasn’t meant to do...". The rest of the article could be replaced with "... so I'm kind of an idiot for wasting 2 years."
"You might want to read this" - particularly "Overall Performance: PHP is rarely the bottleneck (HTML slides)" talks.php.net/show/drupal08/7 :-)
Downvoted your "No it's not platform independent" answer, because that primarily depends on how you integrate with the HTTP server.
So its platform independent as long as you are using a consistent method of integration (surely that's an oxymoron?) but doesn't address the different semantics (and sometimes syntax) around file access, memory management, network connectivity, logging.....(OTOH I accept that some of these things are platform specific in PHP)
6

PHP plugs directly into Apache.

C does not. To connect C with Apache, you'll have to use some secure/fast CGI implementation instead of the off-the-shelf CGI.

C -- as a language -- is a lot of work for building web sites.

Look at Web Frameworks in Python.

Look at Ruby on Rails.

1 Comment

You didn't really answer the question, and some information is incorrect. C does integrate directly with Apache via Apache modules. E.g., mod_rewrite, mod_env, etc, etc. C also integrates indirectly for CGI/FastCGI/SCGI/etc as you've mentioned.
3

What about coding websites in C? How does that work out? Is that platform independent and works on each server?

Writing platform independent code in C is quite possible. (PHP itself is written in C, and there are is ridiculous number of cross-platform programs and libraries written in C, like PostgreSQL and MySQL, Boost and Poco C++).

Writing platform independent web applications, on the other hand, primarily depends on how you integrate with the HTTP server. E.g., if you write a C application that integrates directly with the HTTP server via a compiled module (for Apache or IIS), you're going to end up with less portable code - e.g., writing an IIS module in C or Delphi (which I've seen done, and which eBay originally did) means you are not only locked to Windows but you are also locked to IIS on Windows. The situation is similar when writing Apache modules in C.

But if you write a web application in C that integrates via a common standard with the HTTP server, then yes, you can have quite portable code (albeit code that has to be compiled on each platform). For example, you can use CGI to communicate with the HTTP server using environment variables, or you can use the related standards, FastCGI and SCGI. Again, I've seen this done in practical, commercial applications (both to good effect, and to bad effect).

The debate on native web applications (e.g., written in C, C++ and the like) vs. interpreted web applications (PHP, Perl, etc) often focus on three areas.

  • Code performance. Unless it is written by a brain-dead monkey who didn't get the job for writing fortune cookies, C code will always outperform PHP. However, the bottleneck in your application may not be with the speed and memory consumption of the code, but rather with the input/output routines.
  • Developer productivity. Unless you use a good framework (and part of your question was about feature sets of other languages) you're going to be writing a lot of boiler-plate, repetitive code. E.g., decoding percent-encoded URLs, parsing HTTP POST data, etc. There are frameworks that exist for this in C and C++ (see CppCMS).
  • Portability, as you have mentioned. If you're dead set on writing a web application in C, I would stick with CGI or SCGI.

Comments

1

If your problem is a website or web application that seems too slow, switching languages is probably not worth the effort. There are much more efficient ways to speed things up. One of them would be code caching to avoid the overhead of a fresh compile of your PHP scripts on every page requests. See for example http://en.wikipedia.org/wiki/PHP_accelerator. I've personally used XCache to great effect.

There are many other reasons for websites performing slower than they could, many completely unrelated to the underlying language. YSlow (http://developer.yahoo.com/yslow/) is an indispensable tool to find your bottleneck. To give but one example, combining multiple CSS or JS files included from a HTML page into a single file each can dramatically improve response times.

So bottom line: In most cases, the underlying language is not the culprit. Having said all that, yes, there are faster languages. See the other answers above :)

1 Comment

Yes. Check out HipHop PHP, compiles PHP into C code for like 50% performance increase.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.