sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
mark1822@hotmail.com's Avatar

Writing my serverside stuff in C or in PHP?


Question posted by: mark1822@hotmail.com (Guest) on July 17th, 2005 05:56 AM
Hi,

I am trying to figure out if I should learn C and C++ to write CGI
programs, or if I should just use PHP for my web site.

I want to write a high traffic website that would call executibles a
lot dealing with text.

Are CGI programs written in C faster then PHP script programs?

Nick
5 Answers Posted
nospam@geniegate.com's Avatar
nospam@geniegate.com July 17th, 2005 05:56 AM
Guest - n/a Posts
#2: Re: Writing my serverside stuff in C or in PHP?

Join Bytes! wrote:[color=blue]
> Hi,
>
> I am trying to figure out if I should learn C and C++ to write CGI
> programs, or if I should just use PHP for my web site.
>
> I want to write a high traffic website that would call executibles a
> lot dealing with text.
>
> Are CGI programs written in C faster then PHP script programs?[/color]

It depends on the implementation. Compared to CGI I'd say that PHP would
probably be faster, since PHP doesn't require forking an additional
process each time.

If you were to do it in C for speed, you'll probably want to check into
the API of the web server. (Such as Apache modules) In that case, C
would be faster.

You whould probably ask yourself how valuable your time and portability
are. Doing it in C can cause problems if you wanted to go from one OS to
another. (Or even web server to another)

Depending on the complexity of the application, it'd probably be
cheaper (and easier) to balance the load across multiple servers and use
something like PHP or Java servlets. (java servlets/JSP is slow at
first, but once the JSP's are compiled they run a lot faster)


Jamie

--
http://www.geniegate.com Custom web programming
User Management Solutions Perl / PHP / Java / UNIX

John Thingstad's Avatar
John Thingstad July 17th, 2005 05:56 AM
Guest - n/a Posts
#3: Re: Writing my serverside stuff in C or in PHP?

Using mod_fastcgi the C app will be much faster.
That may or may not matter to you.
(PHP being interpreted is 10-400 times slower than C
depending on what you are doing.)
However time to maket will likeley be 10 times longer for
the C app. You way the pros and cons.

På Fri, 23 Apr 2004 02:12:43 GMT, skrev <mark1822@hotmail.com>:
[color=blue]
> Hi,
>
> I am trying to figure out if I should learn C and C++ to write CGI
> programs, or if I should just use PHP for my web site.
>
> I want to write a high traffic website that would call executibles a
> lot dealing with text.
>
> Are CGI programs written in C faster then PHP script programs?
>
> Nick[/color]



--
Sender med M2, Operas revolusjonerende e-postprogram: http://www.opera.com/
Chung Leong's Avatar
Guest - n/a Posts
#4: Re: Writing my serverside stuff in C or in PHP?

"John Thingstad" <john.thingstad@chello.no> wrote in message
news:opr6wcutu4xfnb1n@news.chello.no...[color=blue]
> Using mod_fastcgi the C app will be much faster.
> That may or may not matter to you.
> (PHP being interpreted is 10-400 times slower than C
> depending on what you are doing.)
> However time to maket will likeley be 10 times longer for
> the C app. You way the pros and cons.[/color]

100 times longer is more like it, as the OP implies that he isn't already an
experienced C/C++ programmer. Text handling is notoriously hard in C/C++,
since there're all sorts of places where memory leaks, corruptions can
occur. Even for a seasoned pro it's a difficult tasks to write something
bullet-proof, let alone a beginner.


Fred the man's Avatar
Guest - n/a Posts
#5: Re: Writing my serverside stuff in C or in PHP?

On Fri, 23 Apr 2004 19:52:32 -0400, "Chung Leong"
<chernyshevsky@hotmail.com> wrote:[color=blue]
>100 times longer is more like it, as the OP implies that he isn't already an
>experienced C/C++ programmer. Text handling is notoriously hard in C/C++,
>since there're all sorts of places where memory leaks, corruptions can
>occur. Even for a seasoned pro it's a difficult tasks to write something
>bullet-proof, let alone a beginner.
>[/color]

"PBCC and CGI"
http://www.powerbasic.com/support/f...TML/002700.html

:-)

Fred.
S Koppelman's Avatar
Guest - n/a Posts
#6: Re: Writing my serverside stuff in C or in PHP?

Join Bytes! wrote:[color=blue]
> Hi,
>
> I am trying to figure out if I should learn C and C++ to write CGI
> programs, or if I should just use PHP for my web site.
>
> I want to write a high traffic website that would call executibles a
> lot dealing with text.[/color]

CGI of any kind is one of the slowest, worst-performing ways imaginable
to do anything. As another poster mentioned, things like Apache's
mod_fcgi make it easy to adapt a CGI to run inside the server for vastly
improved performance, but there's little reason to set out to write a
C/C++ CGI in the first place these days.

C/C++ compiled into native server modules, not as CGI, can indeed be
extremely fast. But practically nobody writes web applications that way
except maybe Google, and not even them for a lot of the things they do.

Nearly every high (VERY high) volume website is now done in the likes of
PHP, Java, Python, Perl, VB Active Server Pages, and other high-level
languages, and none of them ever as a CGI. Yahoo itself is transitioning
away from its own in-house scripting language to PHP. I think their
mapping site uses Python, and I think their shopping site uses LISP. In
the case of interpreted and runtime compiled langauges like Perl and PHP
there are readily available, free, mainstream server modules (e.g.
mod_perl and PHP accelerators) that compile the scripts transparently
the first time they're run and have them running at speeds comparable to
C from there on out.

The exceptions to the rule, where people opt to write a web app in C
these days, are usually for embedded devices where memory is at a
premium, or for the "connectors" that other programming languages like
PHP use to interface with the webserver.

You are probably not doing anything higher-volume than Yahoo. Write your
application in whatever language you and your team will be most
comfortable with and is best suited to the application. A low-level
language like C is probably not that language.
[color=blue]
>
> Are CGI programs written in C faster then PHP script programs?[/color]

No. CGIs that have been made thread-safe and then run under a fast-cgi
module can be, sometimes. But you will spend far more time writing it
and you'll have several times the amount of code to maintain.
[color=blue]
>
> Nick[/color]
 
Not the answer you were looking for? Post your question . . .
197,005 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,005 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors