cgi (perl) vs php

I was wondering what would be advantages/disadvantages of one over other?

I'm going to write homepage for my future company.
Currently I can code perl.... but I also have books on php.

I was thinking why is php so popular?
What would you recommend? Stick to perl or learn php?

I know learning php never hurts... :D
 
killasmurf86 said:
I was thinking why is php so popular?
I think its going from this fact: php works well when you have only ftp access. Hosters need to give only small ftp access, so they push php too. There is easier to handle it cus you can forget about permissions etc.
Also, php give great start for n00bs to make their "Hello world" just via html. On perl you need permissions, script address, put out http headers and its not so easy to start. So they just learn php cus is simple and stay on it forever xD

killasmurf86 said:
I know learning php never hurts... :D
I belive it hurts alot. But not from start - later, when you go serious projects..

p.s. And yes, im perl fan xD
 
I think PHP is more extensible due to the number of extensions available. And it's probably more suited for web design. After all, that's what it was created for.

A lot of people overlook the vulnerabilities when coding PHP though (register globals, SQL injection, etc).
 
CGI as a way to create web applications is as good as dead. There aren't many people around that create sites using CGI. It has it's uses of course but for the most part php suffices. Especially if you combine it with a database backend like mysql or postgresql. Add some nifty html/css/javascript and it'll quickly look good.

If you already know perl php is going to be easy. The syntax is quite the same with only some minor differences. Should be relatively easy to learn it.

Unfortunately I still don't know enough about python to make any serious comments on it. I do know you can create great interactive web sites with it :)

What ever you do, steer clear of flash!
 
+1 for python!

Do not go for CGI php, perl or python. You can use them but you will endup doing something wrong and security is a big issue for custom made apps.

These days you have two options:
1) Use ready to use cms such as Wordpress, drupal, Joomla (to name a few). Most of these comes with APIs, you can extend functionality to suite your business needs. This is what business use.

2) Use php, python. perl, python or any other framework to develop webapps. A Web framework is a collection of modules which allow developers to write Web applications without having to handle such low-level details as protocols, sockets or process/thread management. My personal favorite is Django reamwork.

I use Perl / shell / awk and friends for sys admin automation.

CMS for blog and forums.

And Django is used to write webapp.


I suggest you start with CMS option, see http://www.cmsmatrix.org/


Edit: CGI is not used search for FastCGI and lightweight webserver such as Nginx and lighttpd, this is what people use to write webapps as those are ultra fast modern webservers. E
 
killasmurf86 said:
I was wondering what would be advantages/disadvantages of one over other?

I'm going to write homepage for my future company.
Currently I can code perl.... but I also have books on php.

One thing to keep in mind is that Perl is more of a general purpose language than PHP, the latter of which is meant specifically for web apps. If you need to do a lot of pattern matching, text manipulation, calculation and such I'd surely stick with Perl.

CGI (and I do mean CGI in general, which could be Perl or shell scripts or even binary executables written in C/C++) has some security issues that need to be taken care of, but then again PHP isn't without risks either (SQL injection most notably).

PHP is easy to learn and probably a bit easier to use than Perl (which means quicker development), plus it's probably easier to maintain because it's more popular so more people know it.

But in the end it's kind of a judgement call, I don't think either Perl or PHP is significantly better than the other. I personally still prefer CGI but that's more a matter of habit than anything else.

Hope this helps and doesn't confuse,

Alphons
 
I better take complete CMS or CMF like MODx or somewhat like this and upgrade to site's needs. Its much faster than develop new engine..
 
Has anyone compared the performance of PHP as an Apache module or run by FastCGI? I've heard that FastCGI has better performance, so I'm wondering if I should switch.
 
My site is powered by mod_perl. The requests take about 20-70ms on my test machine here at home. Back when it was CGI Perl, requests took 1600ms, and the code was largely the same. I wouldn't recommend using CGI ever, except in the case of small, kludgy web apps that are used internally and nowhere else.
 
I've been using PHP for a number of years, it's really not a particularly good programming language, but neither is perl IMHO.
My main problem with PHP is that it seems to be a language that isn't particularly well thought out, and it's without any clear direction. An example is the recent GOTO feature someone added for PHP6, someone else then filled a bug report for that ...

There are also a number of features I miss, such as list slicing, better string formating, namespaces ...

It is also very easy to write very ugly code. This is much less so with Python for example...

I've also been using Python for commandline/GUI apps, I need to do some we programming work in the near future and maybe I will try python.
The main advantage of PHP is that it's so widely supported on webservers and that there are so many PHP programmers...

CGI as a way to create web applications is as good as dead.

CGI is not a method for creating webpages, but a method for webserver for running executables.
IMO (fast)CGI it is still the best (most secure/stable) way.
 
You guys might laugh me to death, but right now I need to develop CGI site in C for University (well I needed to write some system as part of my learning process, with some pretty hard to implement requirements, and I figured that Using PostgreSQL with CGI was the easiest way to achieve my goad. Security isn't pretty big concern at this point, but I try to write my CGI as secure as I can think of)

Frankly I's quite easy and I even like it.
Here are resources, that helped me A LOT (maybe it'll be useful for someone else):
http://www.cs.tut.fi/~jkorpela/forms/cgic.html
http://www.purplepixie.org/cgi/howto.php

debugging is also quite easy [at least at my current stage of development], you can write simpel sh script, that will emulate web server behaviour, to set up environment and call CGI app)
 
To quote from the first link/howto you posted:

This document was written to illustrate the idea of CGI scripting to C programmers. In practice, CGI programs are usually written in other languages, such as Perl, and for good reasons: except for very simple cases, CGI programming in C is clumsy and error-prone.

;)
 
Big CGI programs written in C usually like to segfault for no obvious reason. Debugging is not easy when you get into complicated web routines specially related to memory allocation debugging. Few years back I have written a web engine in C that had all the stuff you expect (CMS, Forum, News, etc) would not do that again :p.
 
recently saw an interesting option on MVC Catalyst:

Code:
  sub blog : Chained PathPart('blog') CaptureArgs(0) { }


  sub user : Chained('blog') PathPart('user') CaptureArgs(1) {
      my ( $self, $c, $id_un ) = @_;
      $c->stash->{ message } = "Hello ";
      $c->stash->{ arg_sum }->[0] = $id_un;
  }




  sub view : Chained('user') PathPart('view') CaptureArgs(1) {
      my ( $self, $c, $id ) = @_;
      $c->stash->{ message } .= "World!";
      $c->stash->{ arg_sum }->[1] = $id;

  }







  sub view_page_off : Chained('view')  PathPart('') Args(1) {
      my ( $self, $c, $page ) = @_;
      
      $c->stash->{ arg_sum }->[2] = $page;
      
   $c->forward( 'view_blog_message', [ @{$c->stash->{ arg_sum }} ] );
    
  }
  


  

  sub view_off : Chained('view') PathPart('') Args(0) {
      my ( $self, $c ) = @_;

   $c->forward( 'view_blog_message', [ @{$c->stash->{ arg_sum }} ] );
   
  }



  sub view_page_user : Chained('user') PathPart('') Args(1) {
      my ( $self, $c, $page ) = @_;

      $c->stash->{ arg_sum }->[1] = $page;
      
# print '99';
   $c->forward( 'view_blog', [ @{$c->stash->{ arg_sum }} ] );
   
  }
  


  sub view_user : Chained('user') PathPart('') Args(0) {
      my ( $self, $c ) = @_;

   $c->forward( 'view_blog', [ @{$c->stash->{ arg_sum }} ] );
   
   
  }

all to $c->stash

and methods will be called one after another:

Code:
| Path Spec                           | Private                              |
+-------------------------------------+--------------------------------------+
| /blog/user/*/view/*                 | /blog/blog (0)                       |
|                                     | -> /blog/user (1)                    |
|                                     | -> /blog/view (1)                    |
|                                     | => /blog/view_off                    |
| /blog/user/*/view/*/*               | /blog/blog (0)                       |
|                                     | -> /blog/user (1)                    |
|                                     | -> /blog/view (1)                    |
|                                     | => /blog/view_page_off               |
| /blog/user/*/*                      | /blog/blog (0)                       |
|                                     | -> /blog/user (1)                    |
|                                     | => /blog/view_page_user              |
| /blog/user/*                        | /blog/blog (0)                       |
|                                     | -> /blog/user (1)                    |
|                                     | => /blog/view_user                   |
'-------------------------------------+--------------------------------------'


in other languages has never seen anything ... but it is possible to make?
 
Back
Top