Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
PHP Books Media Programming Software Book Reviews IT Technology

Advanced PHP Programming 189

sympleko (Matthew Leingang) writes "PHP5 has hit its third release candidate, so get used to the idea of using it. George Schlossnagle has written a great book on PHP programming which ought to generate some enthusiasm. But it's not just about PHP5: the book includes great information on everything from coding style to high-level problem-solving. I met George through a friend of mine who works for the Developers Library, and I'm glad to have finally gotten a look at his book." Read on for Leingang's review of Advanced PHP Programming: A practical guide to developing large-scale Web sites and applications to PHP5.
Advanced PHP Programming: A practical guide to developing large-scale Web sites and applications to PHP5
author George Schlossnagle
pages 609
publisher Sams Publishing (Developers Library)
rating 9.999/10 (I don't give perfect scores)
reviewer Matthew Leingang
ISBN 0672325616
summary See subtitle

Many of the previous generation of PHP books were fattened with lots of filler: how PHP imports form-submitted variables into its namespace, definitions and examples of valid XML documents, one-line summaries of every PHP function, even an HTML reference. It's like going to Gallagher's Steak House and filling up on free bread. Ladies and gentlemen, may I submit the Atkins-Friendly PHP book. This is not a book about syntax or data structures. This is a book on how to use PHP in enterprise environments. During my first read, I realized around page 126 that I had already learned as much as I had expected to learn and I was just getting started!

The book is very well written, with a friendly tone that is neither pedantic nor partisan. A knowledge of PHP before version 5 is assumed, and the situations tackled are very much from the real world. The focus goes beyond getting what you want to appear in the browser, too; scaling problems of very large web sites, managing a code base with multiple developers, and building your own extensions to PHP are all discussed.

The author draws most examples from a Unix + Apache + PHP environment, and MySQL is the primary database used. The examples are all in PHP5, but many ideas can still be implemented in PHP4. In other words, you can still learn a lot even if you're committed to PHP4 for the near future.

Part I of the book is called Implementation and Development Methodologies (some of these part and chapter names could be a little less clunky, even if they are correct), and the first chapter is about coding style. After that comes a thorough discussion of the new features of PHP5. These are language aspects that are commonplace in other object-oriented languages (e.g., java and python), but which I admittedly knew little about:

  • encapsulation: the ability to keep object attributes and methods private or protected;
  • static attributes and methods to make class functions or singletons;
  • user-definable constructor, destructor, accessor, mutator, and copier functions;
  • interfaces, which are like abstract classes. A class can implement one or more of these as well as extend a concrete class;
  • exceptions, which allow propagation of errors and warnings back up through the function stack.

Other PHP programming concepts are discussed in this part, such as templating, using the command-line interface, and unit testing. The chapter on Managing the Development Environment includes some CVS basics as well as how to organize and keep separate your development and production environments without breaking what works. Another topic discussed is when to use PEAR classes and when to roll your own.

Part II, Caching, is where the book gets hard-core. Once your application works, how do you optimize its performance and scale it so you can have hundreds of thousands of users?

  • You can use static variables to reduce recalculations, and compile your regexps.
  • You can cache data on the PHP level in flat files, DBM files, shared memory, or even in user cookies.
  • There are also solutions outside of the PHP userspace. The ordinary PHP process takes the text which constitutes the programmer's code and compiles into a assembly-style intermediate code. Then the intermediate code is executed. If a script is executed several times without change, the same intermediate code is created, executed, and thrown away several times. A compiler cache saves this intermediate code and reuses it. The author has developed a free, open-source compiler cache.
  • There are also code optimizers, which eliminate dead code and overly-verbose constants.
  • Reverse proxies also work in web sites to reduce network latency. Latency occurs when a server is stuck waiting for a request to be completed before it can execute. A reverse proxy server only collects requests, then hands them off on a high-speed network to the actual server.
  • This can be made even better with content caching. The proxy can determine if the request requires handling by the PHP webserver at all. If a stale, cached copy suffices, it is served instead.
  • Content compression sends your data over the internet compressed. The client's browser is in charge of decompression.

Part III, Distributed Applications, is of big importance to the developer of medium-sized sites. The author discusses the familiar topics of database interaction (including how to troubleshoot your slow queries), authentication, and session handling. Then a chapter on clustering: how to arrange multiple, redundant servers to create a robust, fail-safe system.

The final chapter in this part covers another hot topic: Web Services. Say you want to edit your weblog entries on a real text editor rather than through a web form. If you have RPC (Remote Procedure Calls) set up on your web server, you need only write a script which manufactures a request to a web service and and ships it out. What's the sales rank on Amazon of the book you just wrote? What's the weather like in Medford, Massachusetts today? These are all jobs for web services. XML-RPC and SOAP are approaching the standards state of usage, so using one of these means you don't have to develop your own RPC client or server library. SOAP is even richer than XML-RPC: it's an all-purpose messaging protocol which is in use by many of the big players in web services (e.g., Amazon, Google).

In Part IV, Performance, the author returns to the optimization question. How can PHP scripts themselves be made to run faster? There are several techniques:

  • Use the apache benchmarker or other load-generating programs to determine which requests take the most time.
  • Use a PHP profiler such as the one the author has written to examine your script line-by-line and determine which function calls are most expensive.
  • Use a synthetic benchmarker (such as the one included in PEAR) to analyze small bits of code and discover how efficiently they do their task. Which is faster: interpolation of variables or string concatenation (the latter, at least before PHP 4.3)? If you don't have a library compiled into PHP, can you implement all the functions in userspace efficiently (not really)?

Part V, Extensibility, is for people who want to adapt PHP on the language level for their needs. This part requires a knowledge of C and a strong grip on your hat! After a discussion of PHP and Zend Engine (the virtual machine on which compiled PHP runs) internals, the author shows how to make both simple and complex extensions. You can add new functions to PHP, add a suite of library wrappers, add and manipulate classes and objects, all using pre-defined macros. In the last chapter, you can extend Zend itself to (say) implement all errors as exceptions, create a PHP Shell, an opcode-dumper, or modify the author's compiler cache or profiler.

I very much enjoyed the book. I have chosen to take the plunge into PHP5 for a new web project, partly because this book convinced me it's worth it. I can't imagine I'm going to use everything I've learned from the book, but I'm glad to know how problems like these are solved.

There are a few typos and misspellings, but that's to be expected in such a large book with limited turnaround time. Definitely recommended.


Matthew Leingang is a Preceptor in Mathematics at Harvard University. He continues to try to integrate web development into his day job. You can purchase Advanced PHP Programming: A practical guide to developing large-scale Web sites and applications to PHP5 from bn.com. Slashdot welcomes readers' book reviews. To see your own review here, carefully read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Advanced PHP Programming

Comments Filter:
  • php-embed (Score:5, Informative)

    by SIGALRM ( 784769 ) * on Thursday June 24, 2004 @04:00PM (#9522515) Journal
    Part V, Extensibility, is for people who want to adapt PHP on the language level for their needs

    This is an often-overlooked advantage in PHP: the ability to use php-embed [php.net] to run embedded PHP within another application. For example, our company has created an HL7 HIPAA-accelerator in C/C++; we chose PHP as the embedded language in our product--by which users can create custom data transformations.

    The reason? PHP is easy to use, loosely-typed (which is an advantage in our project), fast, and of course, free. It was a great decision.
    • Re:php-embed (Score:5, Informative)

      by dinodrac ( 247713 ) <[moc.tibm2] [ta] [nosyllorj]> on Thursday June 24, 2004 @04:08PM (#9522600) Homepage
      Hmm... A first post that wasn't a troll. I'm amazed.

      I've got a couple database applications using PHP that I've been working on for a while - I wasn't aware that PHP could be easily embedded into a C application.

      Obviously, I'd get better performance with a hybrid of C and PHP code, so this actually simplifies quite a few projects for me. (No more mixing PHP, Perl, C, Python, MySQL and TCL on a single application - yay! ;)

      Thanks for pointing this out..
      • Re:php-embed (Score:5, Informative)

        by SIGALRM ( 784769 ) * on Thursday June 24, 2004 @04:21PM (#9522709) Journal
        Thanks for pointing this out..

        Sure. One more thing, the zval integration is easy as pie, something like:

        zval *zarray;
        MAKE_STD_ZVAL(zarray);

        if ( array_init(zarray) == FAILURE ) {
        // ... something wrong
        }

        add_assoc_string(zarray, str_name, str_val, 1);

        ZEND_SET_SYMBOL(&EG(symbol_table), str_tokenlevel, zarray);

        Forgive the poor code above, just the way I remember it... I'll email you the php-embed stuff I have in its entirety.
    • Re:php-embed (Score:4, Informative)

      by nkh ( 750837 ) on Thursday June 24, 2004 @04:11PM (#9522623) Journal
      Why not Lua [lua.org] or Ruby [ruby-lang.org]? They can both be embedded easily (and Lua has even been used in Monkey Island 4). Were there other advantages for PHP?
      • Re:php-embed (Score:3, Interesting)

        by Scaba ( 183684 )

        Just on a guess, I'd say there are a lot more PHP developers out there than Lua or Ruby developers (though Lua looks pretty cool). Besides, Ruby developers are all just ex-Pythoneers who thought Python [python.org] was becoming too popular, and don't really count as developers anyway ;>)

        • Just on a guess, I'd say there are a lot more PHP developers out there than Lua or Ruby developers (though Lua looks pretty cool).

          Hmm. Well, I suspect there yet even more VB programers, so sites shouldmbe done in VBScript, no?

          (Yeah, Im trolling.)

          Besides, Ruby developers are all just ex-Pythoneers who thought Python [python.org] was becoming too popular, and don't really count as developers anyway ;>)

          Oh, but you are so wrong! We're really all just ex-Perlers who thought Pythin was becoming too po

    • Why didn't you use perl instead of PHP? It seems to have all the advantages mentioned above and I would think it would be better suited to the task.

      I know perl is out of vouge these days but I think it's highly under-rated. Does it have such a bad name that people actually avoiding it for projects that it would be good for?
  • most of the books (Score:5, Interesting)

    by joeldg ( 518249 ) on Thursday June 24, 2004 @04:07PM (#9522583) Homepage
    most of the books don't cover the topics of cli-based php which is unfourtunate.
    Things like php-ncurses and php-gtk or even how to properly debug cli apps and it is strange saying there is a large following of PHP commandline (cli) people out there.

    Anyway, always good to see more books at any rate.

    • Re:most of the books (Score:1, Informative)

      by Anonymous Coward
      Um, all you need to know about using the CLI is on this page:

      http://us4.php.net/features.commandline [php.net]

      As for php-gtk, there are much better alternatives. And I don't exactly have much faith in something that's developed and supported by only one developer (the cantankerous Andrei Zmievski no less).
    • Re:most of the books (Score:2, Interesting)

      by name773 ( 696972 )
      and don't forget sockets [php.net]!
      i wrote an encrypted chat client/server combo using php exclusively with ncurses and sockets
      source is here [phism.org]

      it's a bit hard to setup, because it was just a for phun project... man php is great
    • most of the books don't cover the topics of cli-based php which is unfourtunate. Things like php-ncurses and php-gtk or even how to properly debug cli apps and it is strange saying there is a large following of PHP commandline (cli) people out there.

      And don't forget ActivePHP which is a neat little deal for scripting nice little windows based php apps.
  • Latest software (Score:5, Interesting)

    by Ford Prefect ( 8777 ) on Thursday June 24, 2004 @04:11PM (#9522626) Homepage
    PHP 5? Great!

    I've got a bit of a complaint about computer books, in that they frequently concentrate on the latest and greatest versions and brush aside the older versions - the versions that the majority of web hosts might be running, for instance.

    I was looking for a MySQL book a while back, and there were dozens of them on the shelves in the bookshop, but all based around MySQL 4 - not the ubiquitous MySQL 3 that I was trying to learn. Looking through at all the new features can be a bit dispiriting, especially when you're stuck with the older version.

    Anyone else had similar problems?
    • Maybe Amazon used books would help?
    • Re:Latest software (Score:5, Insightful)

      by zapp ( 201236 ) on Thursday June 24, 2004 @04:24PM (#9522736)
      Isn't that why we have used books? Ebay, Amazon, Half.com. I'm sure somewhere you can find a book for an older version of a piece of software.

    • Re:Latest software (Score:3, Insightful)

      by wooby ( 786765 )

      I know what you're talking about, and you're right: new books are about new software.

      Your point about web hosts is also true; it's difficult to find a PHP5 webhost. It takes guts to run a RC on production servers! However, you can be certain that soon enough PHP5 will become as ubiquitous as 4.

      Anyways, just judging by the review, it seems like this book's intended readers are enterprise programmers: people who will leverage more control over their development platform than the average webmaster.

      • With the prices of virtual private servers (VPS) these days, there's abosolutely no reason to be held hostage to your web host's old version of PHP if you want to upgrade. Move your server to a $29/month virtual private server and install whatever the hell you want. After a little less than a year of running a VPS from www.dinix.com, I will never go back to cheap shared hosts. So if you can't find a good host with PHP5, then get a VPS account and host yourself! And no, I don't work for Dinix.
    • not the ubiquitous MySQL 3 that I was trying to learn.

      There are hosting companies that still host PHP3? PHP4 has been out for like FOUR YEARS now...

      I admin my own systems, so I'll be moving to PHP5 as soon after its official release as I can do some regression testing.

      The built-in SQLite is very much reason enough to begin using it with my PHP-GTK based applications!
      • Not PHP 3, MySQL 3. Every externally-hosted UNIX client we've worked with (~10) has been a combo of PHP4 and MySQL 3. I'm counting the days (and there will be a lot of them) until I can use PHP5's XML support and MySQL 4's stored procs/ sub-queries, etc.
        • MySQL 3 is common on shared hosts because there are incompatabilities goign from 3 to 4 that a handfull of older web apps fall prey to.

          Whats worse though is that some 'control panels' (eg Plesk, Ensim as well I think) don't run with 4, or at least come with 3 as the default 'supported' environment.

          There are hosts out there though that are not stuck in the past and do run MySQL 4 now, personally, I wouldn't even give the time of day to a host who runs MySQL 3 and doesn't provide any MySQL 4 server at all.
    • There's no money in backdated books in the eyes of [brick-and-mortar] book stores and publishers (speaking as a former publishing employee). Most people don't realize how cutthroat the computer book market is; particularly when compared to "regular" publishing which has no time barrier(s). "Day and Date" describes when a book is desired to be on the shelf; i.e., a book is on the shelf the same day the software is available for purchase. Many people don't even worry about quality for day-and-date books - th
  • Mysql + Apache 1.x (Score:5, Insightful)

    by john_smith_45678 ( 607592 ) on Thursday June 24, 2004 @04:15PM (#9522661) Journal
    Sigh, I really wish these books would get with the times and start using PostgreSQL (or even Firebird) and Apache 2.x (I assume the book uses Apache 1.x since the PHP developers seem so against 2.x).
    • Apache2? (Score:2, Informative)

      The early versions of Apache 2 really scared a lot of people away. It scared me away. Switched to Apache 1 and things started working again. Now that doesn't excuse my poor skill in the sysadmin realm, but I would doubt I am the only one who had headaches with 2.

      -Phantom
    • For database abstraction, George mentions PDO in his blog as a nice solution.

      http://www.schlossnagle.org/~george/blog/archive s/ 260_PDO.html

      -PM
    • by Anonymous Coward on Thursday June 24, 2004 @04:37PM (#9522846)
      This seems to be a really common misconception among readers of slashdot. The truth is this:
      - PHP developers are not opposed to Apache 2.x.
      - PHP is stable on Apache 1.3 _AND_ 2.x.
      - Apache 2.x has a large number of new features designed to better handle high volume sites (with or without PHP)

      MySQL is still the standard web-hosting provider database backend, that is why most books cover it. mySQL is very similar to other SQL dialects. If you understand SQL, PostgreSQL is easy and you shouldn't need explanation on how to run queries from PHP. The books focus on PHP, not the SQL languages... if you want to learn about SQL, get a SQL book.

      • - PHP developers are not opposed to Apache 2.x.

        At least one (Rasmus) is:
        http://groups.google.com/groups?hl=en&lr=&ie=UTF-8 &c2coff=1&safe=off&selm=caonem%24rg7%241%40FreeBSD .csie.NCTU.edu.tw [google.com]
        • by Anonymous Coward
          you are a ridiculous karma-whoring troll... this is not information, this is what Rasmus has been saying for a while because not all php extensions are thread safe yet. And Rasmus isn't even opposed to apache 2, he's opposed to people encountering an error with those non-thread safe php extensions. After all, Rasmus IS a core apache http server developer as well.
      • by Anonymous Coward
        mySQL is very similar to other SQL dialects.

        Um, no. Not even close. Check out all mysql's gotcha's and deviations from SQL standards:

        http://sql-info.de/mysql/gotchas.html [sql-info.de]
      • by Mr. Slippery ( 47854 ) <tms&infamous,net> on Thursday June 24, 2004 @05:21PM (#9523215) Homepage
        If you understand SQL, PostgreSQL is easy and you shouldn't need explanation on how to run queries from PHP.

        You ought to be using PEAR's DB [php.net] class anyway, which abstracts away most of the differences in dialect.

        • Are there any proper Object-Relational database libraries for PHP yet? PEAR:DB, ADODB etc are all well and good, but they do little more than wrap the various PHP *sql*() functions and abstract away some minor database differences with various levels of success; I've not seen anything which I can point to a database, give it some hints on relationships, and have it generate the majority of my database interface code for me.
      • > Apache 2.x has a large number of
        > new features designed to better handle
        > high volume sites (with or without PHP)

        Yup. We run Apache 2.0 with mod_jk and mod_php on SemWebCentral [semwebcentral.org];, no problems.
      • by Anonymous Coward

        PHP developers are not opposed to Apache 2.x.

        Certainly, noone is opposed to Apache 2.x. It is a very good idea to make PHP work flawlessly with Apache 2, and once some certain technical problems gets corrected everything will be nice.

        PHP is stable on Apache 1.3 _AND_ 2.x.

        PHP is not stable with Apache 2. Rasmus Lerdorf's explanation is widely known, and is part of PHP's FAQ [php.net] now. Basically, many extensions that PHP rely upon don't work well in threaded environments, and it's quite tricky to know exac

    • by mios ( 715734 )
      That's not entirely true. PHP itself is threadsafe ... some third party libraries are NOT ... so if you compile some of the third party libraries w/ php, then you might find yourself in a heap of trouble, and you'll find yourself asking WTF is going on here ... So .. the 'official' thing to say would be to use apache 1.x because depending on what you are compiling into php, you just never know. See? The PHP devs aren't so bad after all.
    • by CHaN_316 ( 696929 ) on Thursday June 24, 2004 @04:41PM (#9522878)
      I think your argument is just a matter of opinion. One could have easily asked

      Sigh, I really wish these books would get with the times and start using SQL Server 2000 (or even Oracle), and Microsoft IIS

      I'm a firm believer of using the right tool for the right job. Some projects I've worked on don't really need foreign key enforcement, and subqueries, and what not provided by PostgreSQL. MySQL has worked just fine in a lot of cases. Some industrial strength applications may need a PostgreSQL. But whatever makes the most sense should be used.
      • I like to compare the situation, with that of hammers and their use.

        There are probably more hammers out there, than we have DB's on offer.
        hammer==database

        So, let's take the 'dead blow' hammer, you wouldn't use it to nail the wood structure of your house together. Well, you might, BUT it's gonna be a pain.

        Now we can take MySQL and use it for developing an app, that is dependent on a strong relational database. Well, you can do it, BUT...see above!
        What the parent poster should rather be asking for is
      • Perhaps part of what the grandparent is trying to point out is that a lot of the /.-related culture revolves around LAMP. That's fine as long as that's actually the best tool for the job -- but people get stuck on things, and if never exposed to other tools won't recognize the better tool when they see it.

        So really, it's not so much that we need more Firebird/Postgresql in books because they're better, it's to make sure that the audience gets a bit of everything. MySQL might be seen as a "teaching database
      • SQL Server 2000, what year is this?

        On a more serious note,
        PHP==free
        Apache==free
        MySql=free
        Postgr esql=free

        IIS=!free
        Oracle=>!free
        SQL Server=!free

        I use Apache 2 because it scales better and Postgres because I already know sql and don't want to spend half my life screaming because MySql doesn't support xyz abc etc...
        Infact I try to avoid having MySql on anything, because I know that if i ever want to extract or archive my data it's going to be a pain.
      • by scrytch ( 9198 )
        > Some projects I've worked on don't really need foreign key enforcement, and subqueries, and what not provided by PostgreSQL

        MySQL not supporting foreign keys is just fine. I just wish it would stop PRETENDING to support them by parsing and subsequently IGNORING foreign key declarations.

        MySQL's documentation has typically heaped scorn on everything they didn't implement that version, then the attitude suddenly disappears when they do get around to implementing it. It strikes me as an astonishingly un
    • I agree that some applications are better off with Postgres but a half way decent abstraction layer and portable queries go a long way. I've changed some of my concurrent update intensive applications to a postgres back-end very easily.
  • that onion article titiled "Student arrested for suspected use of PHP" ...and rightly so ;)
  • by bunnyman ( 121652 ) on Thursday June 24, 2004 @04:45PM (#9522912)
    Isn't that called "Perl?"
  • Advanced PHP (Score:3, Interesting)

    by Deltawolf ( 789706 ) on Thursday June 24, 2004 @04:46PM (#9522918) Homepage
    This book seems like a friendly addition to the many 100s of php books already out there. I have bought many php books and they all seem to go over the same thing, syntax and functions. But this book from the description seems to do more than simply explain functions and syntax but also usability and practical use. I am a php programmer myself and much of the problem of coding programs is high volumes of data and usage. By using a code cache system outlined in this book it would definatly allow many good programs that are out today to be used on a larger scale. I know a bulletin board I coded a year or two back could have used this, it choked at 1000 or so users at once. PHP5 is coming and it looks to me like a force to be reckoned with. While you naysayers who code perl, c, and other languages put down PHP as a pathetic language, PHP5 should be getting on par with perl and other languages.
  • Maybe around 5.3 (Score:2, Interesting)

    I'm thrilled to death that PHP is finally starting to catch up with the rest of the world. A solid XML interface, SOAP support, and OO like behavoir are great steps toward a modern programming language. However after my experience in with the PHP 4 I won't be upgrading anytime soon. Can't deal with the constant configuration changes, changing function behavoirs, bugs, and generally moving target of a language.

    Don't get me wrong I love the current state of PHP for developing small fast websites. But if hi
  • by PeeAitchPee ( 712652 ) on Thursday June 24, 2004 @04:53PM (#9522986)

    There are times when to use a strongly-typed, "true" OO language like Java or C++ and times to use a scripting language like PHP or Perl. Part of being a good programmer is being smart enough to use the right tool for the right job. If you want to torment yourself by over-engineering a small- or mid-sized website in EJB, go for it, but respect those who like being able to get stuff up quickly and easily, with a minimal learning curve. And YES, it is possible to build secure web apps in PHP, despite what you may have heard.

    When you've only got a hammer, everything looks like a nail.

    • There are times when to use a strongly-typed, "true" OO language like Java or C++ and times to use a scripting language like PHP or Perl.

      There is no reason why you should not use scripting *and* Java at the same time. If you use Jython, Groovy or BeanShell you have all the flexibility of scripting combined with access to the full APIs, security and scalability of Java. If you use BeanShell, you can easily convert your scripts into compiled Java source code if that becomes necessary.

      Part of being a goo
    • Where does this impression come from that strong typing is better for larger projects? There is no scientific evidence or clear-cut argument for that claim.
  • Aw, Crap (Score:2, Insightful)

    by Crinos ( 201310 )
    Atkins-Approved? What the crap is that?!

    (I know what it means, but what is it doing here?)
    • Give the guy some credit. He was just trying to add a little suttle humor to his report (bread - atkins/going over allready covered and understood - reading this book).
      What is it doing here?
      What are you doing HERE?
  • Language Bashing (Score:4, Insightful)

    by sfhc ( 709072 ) on Thursday June 24, 2004 @04:56PM (#9523000)
    I wish people would get over language bashing.

    The issue is not weather PERL or PHP or C is better than the other.

    Languages are just tools. Writing good software is a reflection of one's ability to plan, use OOP, and troubleshoot code, just to name a few.

    When faced with a problem that needs solved, you examine the problem, and select the most appropriate tool(language) to get the job done, and hopefully you apply good software writing skills to the solution.

    Even if you think PERL or something is so much better than PHP, but you suck at writing good software, your software is going to suck.

  • by randallman ( 605329 ) on Thursday June 24, 2004 @05:03PM (#9523068)
    PHP was originally developed to make web programming easier in the same way Bash makes certain operating system tasks easier. PHP:Web::Bash:OS.
    PHP5 is impressive, but it appears to be trying to change its scope and here is why. Like Bash, PHP is a big time saver for small programs, but is more difficult to write and maintain as the program gets larger and more complex. The features added to PHP5 will let it scale better, but it will lose its Bash-like advantages. It is trying to move into the arena with Java, ASP.Net(?Maybe), Python, Ruby, ... The problem is you can't have both Bash-like scriptablity and Java-like power/maintainability. So PHP will take the road of Visual Basic -> VB.NET.
    After seeing MY limits with PHP I moved to Python although I still use PHP for simple web scripts. In my opinion, PHP5 is a new language in an old arena. You should choose the right tool for the job, and if you need the new features in PHP, have a look at a powerful, weathered language like Java, Python, or Ruby, or (add your language here).
    • PHP5 does not lose the Bash-like advantages of the language.

      For purely procedural code, PHP5 is EXACTLY the same as PHP4. The only changes have been in object-oriented side of things. And even most of those changes are optional.

      Furthermore, the OO changes to PHP5 bring it in-line with other languages. Ultimately it should make it easier for developers familiar with OO programming to get into PHP.
    • as PHP has grown more complex, it has continued to support and enhance the same basic tools that made it easy to use in the first place. what PHP is doing is making more advanced tools *available*, they're not making them necessary for use of the language. i would compare the maturation more to, say, QuickBasic which added functionality above BASIC while continuing to support its basics rather than the rehaul of Visual Basic into VB.NET

      if i were to say PHP has had a change in scope, i would say that it i
    • The languages you suggest Java, Python, Ruby... take a look at their beginings, their original purpose, functionality, implementations, and I think your perspective of PHP may change
  • I enjoyed this book (Score:4, Informative)

    by billybob ( 18401 ) on Thursday June 24, 2004 @05:34PM (#9523311)
    I'm about 3 months into a ~5-6 month project in PHP. I had never done anything nearly as complicated as I am now, but I have done a lot of PHP programming. Mainly things that took 2 weeks or less.

    I bought this book near the beginning of my current adventure and I learned a lot from it. It's not the typical PHP book that just mirrors the php doc web site. There's a lot of great information in there. I'm still on PHP4 but that doesnt matter, the concepts still apply.

    Thumbs up! :)
  • by LojaK ( 79978 ) <slashdot AT esoteric DOT ca> on Thursday June 24, 2004 @05:36PM (#9523329) Homepage
    I am a sysadmin by profession, working at a mid-sized ISP in Toronto. I chose to be a sysadmin because I don't really enjoy programming -- but the nature of the job dictates that I code to improve efficiency or functionality. Recently I had to work on an in-house web application, and I chose to do it in PHP, but quickly found that the relatively small webapps I've worked on in the past were not much preparation, so I bought this book..

    To borrow a phrase, "in a nutshell", this book is excellent! Some of it is beyond my skills at the moment, but I appreciate every bit. The author covers OO in a way that I understood, and presented real-world solutions that helped me understand. But, IMO, the best part isn't the PHP, it's the operational theory -- the real problems that sysadmins and web programmers face with large websites, caching, load-balancing, scalability. This made the book worth the $80CND I paid for it.

    I highly recommend it!

    -- Steve.
  • How am I to decide what to go with for a web application which has the potential to grow quite a bit? I'm under the impression that going with something like Apache+Tomcat+Struts+databaseOfChoice and using java servlets would be a better platform than just PHP. Or at least it would be more modular and easier to plug in a web based or rich front end.

    Or I'm just thouroughly confused.

    • 99% of all web sites can be developed using scripting languages such as Php, Python, Perl, Asp.NET VB.NET and should be done in these languages
      You'll save so much time and effort!
      From a commercial perspective, we'll see many more companies developing with script technologies because time to market is so critical and the script languages are making alot of improvement. As per a previous post, most decision makers in commericial companies will make a safe decision... Java or C#. They are doing this because
      • Ahh.. and I forgot to add that departments in commerical companies have budgeted for engineers/programmers in specific technologies based on what they are selling/telling their customers. So the customers have been led to believe (i.e marketing/sales) that they need the things (security, exstensiblity, scaleability) that their technology (Java, C# provides). And the customer purchasing the solution needs to sell their choice to their decision makers, and they give the same song and dance and everyones happy
  • Making fun of php? (Score:4, Insightful)

    by -noefordeg- ( 697342 ) on Thursday June 24, 2004 @06:04PM (#9523515)
    I see a lot of posts making 'fun' of PHP/Apache/MySQL. Especially things like large scale applications, hard/difficult maintenance on larger projects and not good at scaling.

    Well. That might be true.... For those few sites which actually DO require 'scalability', easy maintenance when the project get bigger and the target is millions of hits per hour/day for some really heavy computations and what-not.

    But there are SO few of these projects around. So for all of you who thinks php stinks at least try to use the right tool for the right job. From my experience in web-application development in Norway almost every large software company will recommend some closed source, inhouse made, 'superheavy' application for whatever site you want to have. They will use every argument you post here to put their software in a better light than some 'light weight solution' like PHP/Apache/Linux/MySQL/postgresql.
    Seriously, almost no web-sites in Norway targeted at norwegians will ever require 'large scale' solutions. There simply aren't enough people around. Still the companies will push forth their solution on unsuspecting customers.

    I had a e-commerce site I made (using php/apache/mysql, python/perl for backend functionality running on TSLinux), reviewed by a respected IT-consultant company in Norway (Bekk - http://www.bekk.no/). Their conclusion was that it was a good solution, well written, but.... "It should have been made in a java/C# or something like that" Why? Because of scalability.
    It's just absurd. They really don't take into account the target marked for the solution. And the current system setup is running just fine and dandy without any trouble. Should the number of visitors increase ten-fold (which it never will), well... Add some slave database servers and more webservers.
    Suddenly you have the board of directors going: -Uhm, why didn't you write the system in Java. We hear Java is a good thing. Java is scalable. Java is more secure.
    Why? Because it took me such a impossible short time to make the site with php and it's been going for 2 years now, without problems. That's why.
    The solution they would have otherwise chosen would be 10-100 times more expensive, would require expensive servers and would probably take years to develop.
    • by agwis ( 690872 ) on Thursday June 24, 2004 @08:03PM (#9524170)

      "It's just absurd. They really don't take into account the target marked for the solution. And the current system setup is running just fine and dandy without any trouble. Should the number of visitors increase ten-fold (which it never will), well... Add some slave database servers and more webservers. Suddenly you have the board of directors going: -Uhm, why didn't you write the system in Java. We hear Java is a good thing. Java is scalable. Java is more secure."

      I've encountered this a few times myself but I have a different view point on it. I agree that many sites will never grow enough to worry about scalability but the one thing that does almost always happen is new features being added.

      I've personally seen a few PHP sites that run flawlessly but they are not easily extendable. They are written in such a manner that developers are afraid to work with it because it's too easy to break stuff, or adding new features will involve rewriting big chunks of code. I will admit that I've seen this in other programming languages as well such as .asp and .jsp/java.

      If you consider programming styles such as struts [apache.org], cocoon [apache.org], webwork [opensymphony.com], etc. which encourage the MVC pattern it makes huge difference in the maintainability of web applications down the road. I find that java applications tend to use either these types of frameworks or custom ones that follow the same idea while I find many PHP applications are more like spaghetti code that do work fine but are a nightmare to add to in the future. They are quickly built but the lumping of PHP code in HTML makes it hard on projects where designers need to update the look and feel of a website but have no idea how to change their pages without mucking up the code.

      I'm not saying that is the case all the time but what I am noticing is that PHP is gravitating towards OO programming and seems to be encouraging the separation of business logic from presentation logic, which is a very good thing. The argument that PHP is not as scalable as Java really should be more like PHP is not as extensable or maintainable as Java, but this certainly seems to be changing for the better.

      • "I've personally seen a few PHP sites that run flawlessly but they are not easily extendable. They are written in such a manner that developers are afraid to work with it because it's too easy to break stuff, or adding new features will involve rewriting big chunks of code."

        You are 100% correct here. :-/ PHP can be bad because it's so easy to write really really low quality code making it hard to later add more features or for 3rd party programmers to add/use the code. But that is possible in other langu
    • The problem is perception.

      Even developers are subject to it's pressures and allures sometimes. Who wants to pass up something "enterprise-grade", scalable, industry supported, etc. for something that amatuers might use? How can you call yourself a professional when you don't use the best?

      It's all relative to your task. Of course, that might be so obvious as to not warrant hiring a consultant.
    • Should the number of visitors increase ten-fold (which it never will), well... Add some slave database servers and more webservers.


      Post the url of the website on /. and you will be proven wrong :)
  • An excellent book. (Score:3, Informative)

    by veg_all ( 22581 ) on Thursday June 24, 2004 @06:31PM (#9523691)
    I ran across a used copy of this book in The Strand and have to say it has taken its place next to The Cookbook on the shelf of Truly Useful Books. All the "advanced" php books I had found before this one either had a three or four page spread on objects and classes or (in the case of one awful Wrox book) scads of code with little useful description of the considerations that went into its architecture. If you're coming to php from a non-coding background, you'll find that most books seem to stop just before the discussion gets truly interesting (and useful). No, I don't already know how to make use of inheritance, and telling me that it involves extending a class without describing why I would want to do that and how to design classes so it can be done intelligently and powerfully is pretty useless.

    This book deals with those advanced topics in substantial depth. Want to know what strategies should be considered in deciding how far to abstract database classes? Want an in depth discussion of preformance caching? Care to contemplate the values of various distributed architectures? Interested in Zend engine internals? From coding style clear through application benchmarking, this book covers it, and it covers it thoroughly and engagingly.
  • PHP x Java x .NET (Score:1, Insightful)

    by Anonymous Coward
    I think the most difficult decision is which tool/language should you use.

    If you are a programmer it's always good to look around, see what this language can do, specially if better/faster than the current one.

    When you have a software house this can be tricky. I've been doing some development from small sites to small applications and every now and then comes a question: should I change to java (jsp) ?

    Seems that the EJB-something is a great thing but only pays if you have really big projects, otherwise
  • http://www.amazon.com/exec/obidos/ASIN/0672325616 / georgeschloss-20/ [amazon.com]

    That link gives George a bit more money. If you're feeling really generous, visit his blog [schlossnagle.org] and click the little "Buy from amazon.com" button. He gets a larger percentage from those (ironically, more than he'll get from royalties).

  • Good book (Score:2, Informative)

    by Doyle ( 620849 )

    I bought this book a couple of weeks ago. It's very good. I like the way it covers the general topic of "how to write applications well" as opposed to focusing purely on writing in PHP.

    My only criticisms of the book are: (1) It would be nice to see more OO patterns stuff in there (particularly database access patterns), (2) There are a couple of mistakes in the code that got me puzzled for a while. On the whole though, an excellent read.

    • Hrmm...

      If you need patterns, you may as well look at a generic patterns resource like Addison Wesley's excellent book on Application Patterns (ISBN 0321127420). While it has a strong J2EE bent, if you can't adapt a generic idea like a pattern to another language, then you need alot more help than these books provide. It also goes into intricate detail on DB type patterns, levels of abstration and when to choose the appropriate pattern.

      With PHP5, object oriented programming becomes more Java-like, so adapt
  • Here is what is PHP4's OO model is capable of:

    SiG [sourceforge.net]
  • Now if only the PHP devs hadn't totally ignored Unicode support for PHP5, we might have had the perfect weblanguage.
    Now you're still limited to ugly hacks and extensions that the typical PHP installation does not have, and the Americans/Brits are still unaware that there's anything beyond ASCII.

Our policy is, when in doubt, do the right thing. -- Roy L. Ash, ex-president, Litton Industries

Working...