PHP Vs. ASP

Discussion in 'OT Technology' started by Woodmaster, May 1, 2003.

  1. Woodmaster

    Woodmaster New Member

    Joined:
    Dec 25, 2002
    Messages:
    15,448
    Likes Received:
    0
    Location:
    Brasil
    Well, I believe that PHP is alot better than ASP. I believe that it is just as stable and more at times even though most will disagree. PHP is easier to learn, less complex. It is also easier to code with. PHP can do just as much as ASP if not even more. I could go on all day long but I would rather here your thoughts. :naughty: :rant2: :wavey:
     
  2. D1G1T4L

    D1G1T4L Active Member

    Joined:
    May 4, 2001
    Messages:
    16,489
    Likes Received:
    0
    Location:
    Bay Area
    i agree :) (even though i dont know them)
     
  3. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Maybe try ASP.NET instead. A very large improvement to ASP.
     
  4. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    I've done ASP Jscript and I've spent a good chunk of time with PHP (although not in a full on production environment).

    ASP's session handling and error handlign is about all I can think of that really out does PHP (v4). And it really boils down to one additional function call to persuade PHP to handle sessions in the same manner as ASP. PHP doesn't (as far as I know) support try()/catch() which can be pretty handy.

    That and the use of ADO. Although there's phpADO which is an additional code layer to the database functions. See PostNuke for this in action...

    What I find PHP does pretty well:

    - Handling arrays. In particular, $array[$key] where $key can be numeric or a string. The beauty about PHP is you can go back and interrate through the array and pull the key's string names back out. When the key names are strigns, count($array) in PHP still returns a positive number in terms of how many elements are in the array. ASP's array.length returns 0 (I assume its because the key is a string and therefore a pointer to a memory location which for some reason isn't worthy to be tallied with array.length - I find this odd).

    - Addons. ASP's solution to adding additional functionality is via COM objects (DLLs, etc). This was a nifty concept but now is being dropped for .NET (which I haven't played with so I won't touch on .NET). COM objects usually cost money - at least the productive ones do from what I've seen. PHP can access the same COM objects (assuming its being hosted from a Windows box), but also has a ton of add on tools such as the GD library, CURL, and others. PHP can also tap into Perl modules.

    - Handle strings. PHP gives you access to some very very basic string search/replace functions, but also opens up to Perl's regular expression syntax for when you need to get midevil on some strings. ASP's is pretty good as well. PHP just seems to have more support and more options available to you.

    - PHP has a lot more input and output routines built in. Reading a comma delimited file isn't too tough. But with ASP, you have to setup some code to do the parsing. With PHP, it will do it with one function: fgetcsv() (this will read one line, but return each element as an array element). And then there's my favorite sprintf() or printf() (although I don't use them much, they're really nice to have when you need them).

    - Date functions. I must say PHP rules when it comes to playing with date functions. I built an ASP date object add on to simulate all the tricks PHP's date() function can do and only 2 of them I couldn't do because of NT's limitations with time zones (it was really handy, but required about 50 or so lines of code - PHP has all the work done for you). Another nifty PHP trick is the strtotime() function. Wow, with this you can accept practically ANY botched up date from a user and this function will attempt to make some sense of it (great for HTML form date fields and prepping the data for a database - your users will love you for this one!). Good luck doing this with ASP (it can be done, but its rather code intensive).

    - Including code from other files is much easier in PHP. With ASP, you'd have to issue a server side include to bring the file in. Because SSI is processed before ASP, this works, but you may want to exclude an SSI file, and you can't do that with ASP statements. PHP offeres include() and require() as well as include_once() and require_once(), all of which can be wrapped in if() statements or whatever if needed. In theory, this helps reduce your server processing load and allows you to programmatically load what you need and when you need it.

    There's a handful of minor features I think PHP has an edge over ASP. These have just been my observations of JScript versus PHP. I enjoy coding with PHP. It has a lot of the tools I need to create web apps...

    I haven't had a chance to look at .NET so its not fair for me to make any comments on it...
     
  5. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    I may be off my rocker here, but isn't

    PHP & Apache == free
    ASP & IIS (or whatever server you need) == $$

    Seems like an easy choice to me.
     
  6. CruD

    CruD Bah, I'll just hack it

    Joined:
    Oct 25, 2001
    Messages:
    2,796
    Likes Received:
    0
    Location:
    Lakeway, TX
    PHP5 (coming soon) will introduce alot, including Try/Catch.
     
  7. Early Apex

    Early Apex Guest

    Try using a collection or dictionary object in ASP instead of an array. A dictionary (associative array) allows you to iterate keys and items, check for the existence of a key, and of course give you a count method.

    Not if you create them yourself! COM/COM+/DCOM allow easy componentization of tasks. With ASP and a COM-compliant development language, you can rapidly create full OOP multi-server applications.

    ASP & VBScript can use the Scripting.FileSystemObject for very easy input/output functions.

    VBScript's CDate() can work wonders on various date strings.

    Not true. ASP can conditionally include files with scripting logic. For example:

    Code:
    <%
    If 1 = 0 Then
    %>
    <!--#include file="test.html" -->
    <%
    End If
    %>
    where the "test.html" contains, for example, <%=Now()%>, will not write out the time. But change it to 1 = 1, and the page will include the file that writes the time.

    ASP vs. PHP really is down to personal preference. There's not much you can do in one language you can't do in the other.
     
  8. Early Apex

    Early Apex Guest

    IIS 5.0 is included, no extra charge, with Windows 2000 Server.
     
  9. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Hey now! What a deal! :p
     
  10. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    :yum:
     
  11. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    where in phx are you?
     
  12. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Yeah, there's dictionary objects. Notice the difference between "array" and "object". I'm all about object oriented-ness, but all I need is an array and to treat my variable like an array. You've got the added overhead of creating the object and closing down. PHP makes this seemless to the programmer, hence an easier coding experience.



    You go write an ASP/IIS graphics library for generating PNG/JPG/BMP. I admit, I don't have the skill set to go do that, but PHP has 8+ different graphic libraries that plug right in (the alternative would be to buy something, so thats where my statement came from). COM (and all flavors of) usually requires someone with Windows coding experience and even then you're still on shakey ground (my last company has to shut down web services every 24 hours because of a memory leak in a COM object and they have 2 pretty hardcore Windows coders doing COM development).


    The filesystemobject gives you just enough tools to get the job done. PHP goes the extra mile in my opinion with functions that dump directly to the output stream, can create an array from the stream, and my favorite (and as mentioned before) handle CSV files on its own (I mean it parses the sucker for you - no coding involved here). The FileSystemObject doesn't do this for you. You can still do it, but you have to code it yourself.

    Yes, CDate is pretty flexible, but lets see it do this:
    date()


    So close but you failed to understand how IIS handles SSI, ASP, and HTML, and then deliver it all.

    IIS makes a sweap on the file checking if it needs to process it or not. It first looks at SSI and makes any SSI modifications or includes. So we start out with your example:

    Code:
    <%
    If 1 = 0 Then
    %>
    <!--#include file="test.html" -->
    <%
    End If
    %>
    
    After SSI processing:

    Code:
    <%
    If 1 = 0 Then
    %>
    <%=Now()%>
    <%
    End If
    %>
    
    Now IIS does the ASP processing. In your example (and I know, its just an example), you've got the ASP processing engine switching to ASP mode as it enters the IF, then out of ASP and then back in to process the Now() and then back out and then back in to end the if. With the Zend engine for PHP, this approach is actually encouraged somewhat. With ASP, you will get a slow down. If its done a few times here and there, you won't notice it. Do it with a file of 1000+ lines and you've got a performance hit.

    Thats minor.

    Here's my real beef with your above example. EACH AND EVERY TIME you execute the ASP code, test.html gets included. Granted, with the IF statement, your skipping around it so it never gets executed, BUT test.html is still getting included with the SSI processing. Start working with ASP include files (such as libraries and classes) that are even 400+ lines and things start getting messy and you start taking a performance hit (its not overly noticable). This is something that can easily be fixed, but ASP doesn't give you the facilities to do so.

    Here's a PHP example: (the file test.html will contain something very similar to the ASP example you used: <?=time()?> but its time format is a little different, but it will work for this example)

    PHP:
    <?
    if(
    == 0)
      require(
    'test.html');   // include('test.html') would work just as well
    ?>
    Here, the require() function does NOT include test.html until the if() condition becomes true so you save on processing overhead to include test.html until the PHP code dictates it must. ASP does not give you this level of control. PHP still allows for SSI and SSI will be processed before PHP (just like in the ASP example) but instead of using SSI, let the scripting engine do the work.

    This is true and I'm all about using the right tool for the right job. This point could be argued that PHP runs on NT and *nix while ASP is rather confined to NT (although there's chilisoft ASP but at $125+ you might as well find an NT box).
     
    Last edited: May 3, 2003
  13. Woodmaster

    Woodmaster New Member

    Joined:
    Dec 25, 2002
    Messages:
    15,448
    Likes Received:
    0
    Location:
    Brasil
    Good thoughts.... good thoughts.... i can't wait to see what php5 offers
     
  14. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    I almost forgot about this trick:

    PHP picks up on a lot of Perl's string tricks like this one (although I admit I don't use it all that much):

    PHP:
    $myvar 'This is a string';    // note the single quotes
    echo $myvar;                     // nothing exciting here but prints $myvar

    echo "Myvar is: $myvar";      // works and prints: Myvar is: This is a string
    echo 'Myvar is: $myvar';      // still works, but prints: Myvar is: $myvar
    Here the double quote tells PHP to parse the string while the single quote tells PHP to treat the string as a string and don't try to parse it (this essentially saves you processing time). An interesting note is how PHP then handles the carriage return line feed escape character "\n". In PHP, echo "\n" and echo '\n' will produce two different results. "\n" will actually tell PHP to produce the escape character control character while '\n' tells PHP to treat this as a string and will print '\n'.

    With ASP, you have to resort to concat. the strings, which PHP allows too but instead of the plus sign, PHP uses the period character (swiped from Perl).

    When I say PHP has some nifty string tricks, this is what I'm referring too. And typically if you're producing a web app, you're bound to have some sort of string processing...
     

Share This Page