C Board  

Go Back   C Board > Community Boards > Tech Board

Reply
 
LinkBack Thread Tools Display Modes
Old 10-13-2009, 09:28 AM   #1
Unregistered User
 
Yarin's Avatar
 
Join Date: Jul 2007
Posts: 925
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?
__________________
GCC 4.4.0, Code::Blocks 8.02, Fedora 11, x64
Yarin is offline   Reply With Quote
Old 10-13-2009, 09:41 AM   #2
Wheres the lesbians?
 
mike_g's Avatar
 
Join Date: Oct 2006
Location: UK
Posts: 1,219
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.
__________________
Senior highbrow doctor of authority.
mike_g is offline   Reply With Quote
Old 10-13-2009, 09:49 AM   #3
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
Quote:
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.
bithub is offline   Reply With Quote
Old 10-13-2009, 10:05 AM   #4
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
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...
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS

Last edited by MK27; 10-13-2009 at 10:48 AM.
MK27 is offline   Reply With Quote
Old 10-13-2009, 11:11 AM   #5
Unregistered User
 
Yarin's Avatar
 
Join Date: Jul 2007
Posts: 925
@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??
__________________
GCC 4.4.0, Code::Blocks 8.02, Fedora 11, x64
Yarin is offline   Reply With Quote
Old 10-13-2009, 11:48 AM   #6
Registered User
 
Join Date: Nov 2007
Posts: 171
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
NeonBlack is offline   Reply With Quote
Old 10-13-2009, 12:39 PM   #7
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,944
"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...
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS

Last edited by MK27; 10-14-2009 at 09:09 AM.
MK27 is offline   Reply With Quote
Old 10-13-2009, 01:04 PM   #8
Registered User
 
Join Date: Jul 2007
Posts: 44
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 01:07 PM.
fronty is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unknown memory leak with linked lists... RaDeuX C Programming 6 12-07-2008 04:09 AM
My program isn't inserting a new node in the beginning of the list... RaDeuX C Programming 3 12-06-2008 07:54 PM
PHP installation ssharish2005 Tech Board 8 11-23-2007 09:42 PM
Binary Search Tree penance C Programming 4 08-05-2005 05:35 PM
PHP on my Computer! xxxrugby Tech Board 4 03-15-2005 09:34 AM


All times are GMT -6. The time now is 11:41 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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