DanielGibbs
DanielGibbs

Reputation: 10191

PHP vs. C CGI for small web service

I am creating a small web service which will only be accessed by machines, not users that simply takes a query string and makes a few MySQL queries. I decided to code this in PHP because it is simple and easy to write and does its job well. My boss however, wants we to write it as a CGI in C (using FastCGI) because he says it will be faster and use less memory. I'm not so keen on this idea for a few reasons:

But that's just my opinion. What other factors do I need to take in to account? Is C the best tool for this job? Or is PHP?

Upvotes: 7

Views: 4992

Answers (8)

Flavius
Flavius

Reputation: 13816

Ask your boss if it wouldn't be better if you used C++.

  • Remind him about the maintainability of the code, and that with C++, you can introduce less bugs, at the price of just little speed.
  • Remind him that the "time" needed for fixing or improving software is "included" in the "execution time" - the time you'd have the services suffer because of a little mistake.

And try fastcgi++. You've also got boost and other libraries which can help you do the boring stuff faster, and concentrate on WHAT MATTERS.

And if the application does lots of calculations, it is a good idea to make it in C / C++.

  • Otherwise remind your boss that usually, no matter the language, the application won't be slowed down by computations, but by "waiting for resources" - waiting for the disk or waiting for the database are the most prevalent ones - which happens no matter the language.
  • Remind your boss that for the speed, you can get about 10-60% improvement by using apc.

If he simply doesn't want, then you have two choices:

  • quit the job
  • do as he asks you to

Why C++, and not C

It is true that with good coding conventions, you can write manageable code in C too.

But with C, you still have the verbosity of error handling, as opposed to exceptions, of NUL-terminated strings, of maps or what not. I love C too more than C++, but let's face it: here is not about the language, it's about the mentality of a despot (the boss) who needs to be fought with arguments and learn to lend an ear to his employees.

Upvotes: 1

duedl0r
duedl0r

Reputation: 9424

shudder... You should leave the company. A boss shouldn't be allowed to micormanage the workers... unless he's also the programming guru of the company :)

Upvotes: -1

esamatti
esamatti

Reputation: 18953

Your app is most likely I/O bound. So it won't even be noticeable faster in C.

Upvotes: 0

Lumi
Lumi

Reputation: 15264

If speed is your (or your boss's) concern, check out the G-WAN server, which allows allows you to write C scripts. There are some MySQL samples in the forum. It'll be much faster than FastCGI (which has to cross process boundaries via sockets).

Upvotes: 3

Ivan
Ivan

Reputation: 15922

Some points about this:

  • It's much easier to implement any web service in PHP rather than C, because PHP is a language designed to work online and C is a general language.
  • C is compiled and this makes it much faster than PHP programs, but if you are really worried about optimization (your program consumes a lot of resources and your hardware is very limited) you can use PHP "accelerators" that compiles the source (for example)
  • Access to databases is equal penalized in both languages, so if your program has to access a lot to DB, it will have a similar performance.
  • The more important: the boss is the boss :)

Upvotes: 2

Greenisha
Greenisha

Reputation: 1437

IMHO, if most processing is made by MySQL, there is no need to write this code in C, because difference is negligible, but if there is much processing will be made by your code, it makes sense to listen to your boss and make it in C

Upvotes: 1

Pan Pizza
Pan Pizza

Reputation: 1034

You got no choice because your boss want it. Unless you can't code in C then just C it.

Upvotes: 0

IvanGL
IvanGL

Reputation: 767

Both tools are ok. If your boss wants C, made it in C.

Upvotes: 0

Related Questions