is C++ or PHP the best option?

This is a discussion on is C++ or PHP the best option? within the Tech Board forums, part of the Community Boards category; I'm looking to make a dynamic web page that'll see a lot of traffic. Would a CGI application or a ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,690

    is C++ or PHP the best option?

    I'm looking to make a dynamic web page that'll see a lot of traffic. Would a CGI application or a PHP script be better suited for this job? I know CGI will execute way faster than PHP. With PHP, it has to be parsed, but (correct me if I'm wrong) it doesn't need to create a seperate process like PHP.
    Besides difficulty in coding, speaking strictly preformance, which would be better?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Are you going to be using a database? If so, then thats usually where the bottleneck will end up. PHP should be fine, loads of very busy sites use it. And if speed was an issue I'd rather fork out for a faster server than spend all the extra time dealing with C++ for text processing. Obviously you could get better performance using C++, I just don't see the point for websites.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    Besides difficulty in coding, speaking strictly preformance, which would be better?
    Strictly performance? A C application with an embedded webserver (like libmicrohttpd). Of course I would much rather use PHP than C or C++ for web development, but you asked from a strictly performance standpoint...
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Yarin View Post
    I'm looking to make a dynamic web page that'll see a lot of traffic. Would a CGI application or a PHP script be better suited for this job? I know CGI will execute way faster than PHP. With PHP, it has to be parsed, but (correct me if I'm wrong) it doesn't need to create a seperate process like PHP.
    Besides difficulty in coding, speaking strictly preformance, which would be better?
    I knew the answer to this question was "perl" when I saw the title

    If you already know perl and have not learned any php (I'm guess you don't know php, or you wouldn't bother asking) you may want to google "perl mason" which works under apache mod_perl. That means perl is kept loaded -- no need to launch a process -- and executes as fast as the underlying C code. Mason allows you to embedd perl in html templates -- the same way as php -- but even with plain ol' CGI, mod_perl itself increases the performance by something like 600-700%. Meaning apache will deal with 500+ requests per second constantly without slowing down* depending on the hardware it's running on. Actually, here's a test I just did on my eeny-meeny vps mod_perl server:
    Code:
    Concurrency Level:      10
    Time taken for tests:   1.860 seconds
    Complete requests:      5000
    Failed requests:        0
    Write errors:           0
    Total transferred:      1660000 bytes
    HTML transferred:       470000 bytes
    Requests per second:    2687.75 [#/sec] (mean)
    Time per request:       3.721 [ms] (mean)
    Time per request:       0.372 [ms] (mean, across all concurrent requests)
    Transfer rate:          871.42 [Kbytes/sec] received
    2600+ requests per second, but that is a nominal cgi style script:
    Code:
    #!/usr/bin/perl -w
    
    my $r = shift;
    $r->send_http_header('text/plain');
    print "Hello world\n";
    A normal page with css, js, embedded code, images, such as the chat login page, is much much less per page -- but in that case, there are, of course, multiple requests per page. Still, the login for the chat (below), which involves multiple images and server-side processing, can be served up like 5-10 times a second...bombing the server with 50 requests, 2 at a time, the longest one takes 4.5 seconds, and 75% (of the 50) are completed in <0.2 seconds, 95% in <1 sec.

    If you don't know either php or perl, php is more common for this and much easier to learn, methinks, but there are a lot of advantages to perl; eg, with my private chat server, qv.
    OMG! Live chat w/ MK27!
    the parallel server** is written in perl, but it can share modules with the embedded code in the html pages -- meaning 1) less memory usage 2) less code duplication (validation routines, etc). And best of all, you can save your brain for perl and forget php.

    FYI, Amazon.com uses perl mason instead of php.

    If you don't know either, and you just want to do a lot of typing, use C++. But I very much doubt the "bottlenecks" in a web server will be in anyway improved by using a complied app to generate the pages.

    *so I'm not sure what you mean by "high traffic", but I really really doubt this is an actual issue. Even a normal cgi setup should serve like 100 requests per second.
    ** by which I mean, not apache itself, but a persistant program that handles certain details (requiring persistance) in the background, then serves them up to apache. Sort of like how a dedicated database server might work if it were RAM based...
    Last edited by MK27; 10-13-2009 at 11:48 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,690
    @MK27: Typo, I meant to say "got any good references to learning *perl* for web dev?". Sorry

    Can anyone here tell me what RonR is??
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  6. #6
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Ruby on Rails
    It's just a fad.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    "Ruby on Rails" is a system that allows you to use ruby in a php-like embedded fashion. I actually learned ruby just for that.

    My problem with RonR is that is exclusively a MVC arrangement -- I think ASP is also this way. There are a lot of good things about MVC, but IMO it makes many things easier, many other things unnecessarily complex (because even "hello world" uses a database ), and some things impossible or extremely awkward.

    In the course of learning RonR I found out about Mason, which is kind of a well kept secret or something -- eg, I could not find a short beginner tutorial on the web. So after I got the hang of it, while all my "beginner" type concerns were still fresh in my mind, I wrote one:

    TUTORIAL: Intro to Embedded Perl Using Mason

    There's also an online version of the 1st edition of an O'Reilly book ("Using Mason") that's linked in the tutorial. There is also
    Mason HQ: Welcome to Mason
    which most of my subsequent "How the heck..." searches seem to end up there. There's also a mailing list, which as long as I've been watching it, people seem to get quick help, <12 hrs. (BTW the tutorial got looked over and approved by the mailing list, which includes the developers)

    If you don't know perl tho, before you start seriously you would have to learn
    • standard stuff (loops, functions, arrays)
    • HASHES, HASHES, HASHES
    • regular expressions fer sure
    • REFERENCE REFERENCES REFERENCES
    • at least some understanding of object notation, since the modules use that, altho you do not have to do any OO yourself


    I don't know why Mason is (apparently) so much less prevalent than php and RonR -- perhaps because most of the old school perl gurus just do everything with cgi. Since I've never used php much, I can't say with authority what's "better" but I think they are probably both about as flexible as you could want, within the constraints of how the web works. Which vis dynamic content, you have two places where the content is dynamized:

    Client side: code is downloaded and run on client, javascript, java applets, flash, css can be dynamic...

    You can't download a whole database and most people wouldn't want you to, so there's server-side; kind of "expensive" because the server has to do it. That's CGI (any language) and the server-side scripting languages, ASP, php, perl (there are several other ways besides mason), ruby, also PYTHON can be embedded via Django, but that too is strictly MVC (I believe).

    Definately php was invented for the web by a german academic, initially, just for himself. It stood for "personal home page" scripting, altho now it has a recursive joke acroymn...
    Last edited by MK27; 10-14-2009 at 10:09 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    PHP: write web pages and some programs if you are insane and don't want to use any language which suits better for that job.

    Perl: write web pages, write anything else or just check CPAN, because the program you need is already written.

    Ruby on Rails: Does even /. use this?
    Last edited by fronty; 10-13-2009 at 02:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Replies: 3
    Last Post: 12-06-2008, 07:54 PM
  3. PHP installation
    By ssharish2005 in forum Tech Board
    Replies: 8
    Last Post: 11-23-2007, 09:42 PM
  4. Binary Search Tree
    By penance in forum C Programming
    Replies: 4
    Last Post: 08-05-2005, 06:35 PM
  5. PHP on my Computer!
    By xxxrugby in forum Tech Board
    Replies: 4
    Last Post: 03-15-2005, 09:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21