May – Using the APD debugger

Far to long I have wanted a simple way to dump a call stack or retrieve
a simple profile. How long does this group of functions run? Which ones are
hit the most frequently? You know how it is…you use print statements
or logging to find your way. No longer…now there is a better way. Now, there
is APD: This month in PUG.

Caveats

I must clear the air first. There are a couple of things to keep in mind before
you try to use this.

Some things to keep in mind

  • Part of PECL (the C library counterpart to PEAR) but does not ship with PHP.
  • Being a compiled zend extension you will need access to your php.ini. This may be a problem if you are using a hosting provider
  • It will work on Windows, but you will most likely need MSVC. I can’t attest to this though…It does work well on RedHat Linux 8. 😉
  • Remember: as with all Zend Extensions, take care if you are running this on your production server. It will be getting intimate with your engine…and it is version 0.6. 😉

So, what does this do?

APD may save your life. It may feed your cat. It might even help you take our your land-lady’s garbage.

At the very least, php-apd WILL produce a trace of your running PHP script. That alone, is a big deal. In addition to a human-readable trace of your program’s execution, php-apd also comes with a “reporting” tool to digest the info for you.

Not quite following? Well, that’s what examples are for!

Here is a typical run for a pice of content where most of the dynamically generated content has already been cached. To get something similar, just put the following at the start of your program:

    apd_trace(99);

Then hit your page as usual. You will get a trace file, ready for analysis. Just point pprofp at it:

    $ pprofp -u pprof.01581
    Trace for /vol1/home/dholmes/site_html/www.remote-clean/admin/common.inc
    Total Elapsed Time =    1.14
    Total System Time  =    0.05
    Total User Time    =    0.79
    
    
             Real         User        System             secs/    cumm
    %Time (excl/cumm)  (excl/cumm)  (excl/cumm) Calls    call    s/call  Memory Usage Name
    --------------------------------------------------------------------------------------
     25.3  0.23  0.23   0.20  0.20   0.01  0.01   879   0.0002    0.0002       199816 mysql_fetch_array
     17.7  0.17  0.17   0.14  0.14   0.00  0.00  2239   0.0001    0.0001         3048 strlen
      7.6  0.07  0.07   0.06  0.06   0.00  0.00     5   0.0120    0.0120       701608 require_once
      5.1  0.02  0.02   0.04  0.04   0.00  0.00   192   0.0002    0.0002        51008 is_object
      5.1  0.04  0.04   0.04  0.04   0.00  0.00   114   0.0004    0.0004           40 is_resource
      3.8  0.08  0.08   0.03  0.03   0.00  0.00    53   0.0006    0.0006          568 mysql_query
      3.8  0.04  0.15   0.03  0.12   0.00  0.01    15   0.0020    0.0080       352048 include_once
      2.5  0.18  0.18   0.02  0.02   0.00  0.00   182   0.0001    0.0001        32616 sizeof
      2.5  0.01  0.01   0.02  0.02   0.00  0.00   183   0.0001    0.0001        -2760 is_array
      2.5  0.00  0.00   0.02  0.02   0.01  0.01    53   0.0004    0.0004          848 mysql_select_db
      2.5  0.04  0.28   0.02  0.23   0.00  0.02   871   0.0000    0.0003         6104 db_mysql->fetchrow
      2.5  0.02  0.02   0.02  0.02   0.01  0.01     2   0.0100    0.0100       278768 define
      2.5  0.01  0.01   0.02  0.02   0.00  0.00    79   0.0003    0.0003      -130896 get_class
      2.5  0.02  0.02   0.02  0.02   0.00  0.00   159   0.0001    0.0001         9776 preg_match
      1.3  0.01  0.01   0.01  0.01   0.00  0.00    53   0.0002    0.0002         2536 mysql_num_rows
      1.3  0.00  0.00   0.01  0.01   0.00  0.00   123   0.0001    0.0001        10128 preg_match_all
      1.3  0.01  0.25   0.01  0.21   0.00  0.02   881   0.0000    0.0002       148016 db_mysql->fetchinto
      1.3  0.01  0.01   0.01  0.01   0.00  0.00    23   0.0004    0.0004         2440 split
      1.3  0.00  0.00   0.01  0.01   0.00  0.00     1   0.0100    0.0100        -3408 resourcerendertoolsbox->getjs
      1.3  0.00  0.00   0.01  0.01   0.00  0.00    17   0.0006    0.0006         3272 method_exists
    

Not to shabby. We made 879 database calls…which seems a little excessive. But, it is MySql: The down and dirty fastest database on the planet (IMHO). Keep in mind, this is a pretty large framework that has never really had any optimizing. So, what do things look like when that same piece of content is not cached?

    $ pprofp -u pprof.01171
    
    Trace for /vol1/home/dholmes/site_html/www.remote-clean/admin/common.inc
    Total Elapsed Time =    5.04
    Total System Time  =    0.12
    Total User Time    =    3.46
    
    
             Real         User        System             secs/    cumm
    %Time (excl/cumm)  (excl/cumm)  (excl/cumm) Calls    call    s/call  Memory Usage Name
    --------------------------------------------------------------------------------------
     54.0  2.04  2.04   1.87  1.87   0.03  0.03  27917   0.0001    0.0001        25728 strlen
      5.8  0.24  0.24   0.20  0.20   0.00  0.00   958   0.0002    0.0002       268008 mysql_fetch_array
      4.6  0.11  0.11   0.16  0.16   0.00  0.00   686   0.0002    0.0002        65320 get_class
      2.9  0.31  0.31   0.10  0.10   0.00  0.00   825   0.0001    0.0001       102424 sizeof
      2.6  0.11  0.11   0.09  0.09   0.00  0.00  1317   0.0001    0.0001        45320 is_array
      1.7  0.06  0.06   0.06  0.06   0.00  0.00   137   0.0004    0.0004        37960 split
      1.7  0.02  0.02   0.06  0.06   0.00  0.00   415   0.0001    0.0001         5560 is_resource
      1.7  0.12  0.12   0.06  0.06   0.01  0.01   578   0.0001    0.0001         8936 file_exists
      1.4  0.04  0.04   0.05  0.05   0.00  0.00   329   0.0002    0.0002        13608 trim
      1.4  0.20  0.27   0.05  0.12   0.02  0.03    22   0.0023    0.0055       885720 include_once
      1.4  0.04  0.04   0.05  0.05   0.01  0.01     4   0.0125    0.0125       586632 require_once
      1.2  0.05  0.05   0.04  0.04   0.00  0.00   571   0.0001    0.0001       -61280 in_array
      0.9  0.80  0.80   0.03  0.03   0.01  0.01   156   0.0002    0.0002          776 mysql_query
      0.9  0.07  0.07   0.03  0.03   0.00  0.00   424   0.0001    0.0001        24600 preg_match
      0.9  0.03  0.03   0.03  0.03   0.00  0.00   156   0.0002    0.0002       -33720 db_mysql->modifyquery
      0.9  0.07  0.07   0.03  0.03   0.01  0.01  1028   0.0000    0.0000        72280 is_object
      0.9  0.04  0.29   0.03  0.26   0.00  0.00   871   0.0000    0.0003         6152 db_mysql->fetchrow
      0.9  0.00  0.28   0.03  0.11   0.00  0.00   327   0.0001    0.0003        -1192 sm_sitetag->getvar
      0.9  0.02  0.28   0.03  0.23   0.00  0.00   984   0.0000    0.0002       159352 db_mysql->fetchinto
      0.6  0.01  0.01   0.02  0.02   0.00  0.00   161   0.0001    0.0001         8632 mysql_escape_string
    

Oh, my! When I saw this the first time, my jaw almost hit the floor! I’m spending almost 2 full seconds calling STRLEN??? There has got to be something going on.

So, I found a problem…what now?

Well, you will need to fire up those deductive reasoning skills they pay you for: Ok, so I know that this is happening when the main pane of content is being generated since it isn’t showing up when that content is cached. I doubt I use strlen THAT many times…maybe if I do a recursive grep on my source tree I can look for something that may suggest something.

Well, it turned up one hit that may be causing it. My gut says that it isn’t related and sure enough it was a dead end. So, time to go the distance. Time to see the log.

If I generate a “calltree” from my log (which takes a very long time on a 2.5M log) I see the problem right away. The log is filled with little gems like this:

    $ pprofp -t pprof.01171 > calltree.txt
    
    --------SNIP---------
    db_mysql->getone
      settype
      sizeof
      db_mysql->prepare
        split
        strlen (371x)
        end
        key
      db->iserror
        is_object
      db_mysql->execute
    --------SNIP---------
    

All of my prepares are hitting strlen anywhere between 100 and 500 times!! Notice that I’m hitting strlen here 371 times, but I’m calling getone…which means I wanted something tiny RIGHT NOW. Tisk, tisk…it’s in PEAR_DB. Well, let’s crack it open and take a peak.

First I look in DB/mysql.php. However, there is not a prepare function defined in there…it must be in DB/common.php.

    // ------------SNIP--------------
    function prepare($query)
    {
        $tokens = split("[&?!]", $query);
        $token = 0;
        $types = array();
    
        for ($i = 0; $i !!!!!!!!!modifyquery
    

Not too bad for 5 minutes of work! (I opened a bug report the next day and it is now fixed, btw.) Of course, the next culprit is now reveled. Again, looking at the tree it is in the same function! This time, it’s the second half.

        $this->prepare_tokens[] = &$tokens;
        end($this->prepare_tokens);
        
        $k = key($this->prepare_tokens);
        $this->prepare_types[$k] = $types;
        $this->prepared_queries[$k] = &$query;
        
        return $k;
    

Which, brings us to the second half of performance tuning: Sometimes, you just can’t do a darn thing. Essentially, their prepare_tokens array only contains a few elements, but by the end of the program they are spaced pretty far apart. This makes end run for a while. It might be helpful to track the index of the last element…but I’ll cop out and just say “this ain’t my library.” 😉

It’s so cool! It must be impossible to install!

Not at all. Just follow the directions in the readme. It’s no more difficult to build and install (in UNIX anyway) than a simple little C program. 🙂

First untar it:

    $ tar -xzf apd-xxxx.tgz
    $ cd apd-xxxx
    $ phpize
    $ ./configure
    $ su -c "make install"  (as root)
    

You can use your phpinfo() to find your extension dir. If I recall I had to manually copy my apd.so by hand. So make sure it exists in your extension directory.

Next, open your php.ini. Again, use your phpinfo to make sure you have the right one.

Check the readme for the proper usage, but in my case I added:

    zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20020429/apd.so
    apd.dumpdir = /tmp/dump_dir
    

Again, this is for my case only…your milage WILL vary.

Restart apache and poof! Add a comment if/how you got this running in windows. 😉

What about the callstack?

Perhaps one of it’s coolest functions for you development pleasure is apd_callstack (and the related apd_cluck and apd_croak). If I know it is blowing up somewhere, but I just can’t for the live of me figure out how it got there…you can have it die with a callstack. For instance, If I add the following line in some obscure module:

    apd_croak();

Then, what I get as output is a callstack just before it dies.

    croaked at /vol1/home/dholmes/site_html/www.remote-clean/admin/lib/catalog.inc line 204
    courses->courses() called at /site_html/www/admin/lib/catalog.inc line 142
    acadofferingsrender->_renderclasses() called at /site_html/www/admin/modules/catalog/AcadofferingsRender.mod line 106
    acadofferingsrender->modulethink() called at /site_html/www/admin/modules/catalog/AcadofferingsRender.mod line 258
    acadofferingsrender->run() called at /usr/local/lib/php/siteManager-2.2.0/lib/modules.inc line 93
    resourcerender->modulethink() called at /site_html/www/admin/modules/resource/ResourceRender.mod line 258
    resourcerender->run() called at /usr/local/lib/php/siteManager-2.2.0/lib/modules.inc line 434
    sm_layouttemplate->_runmodules() called at /usr/local/lib/php/siteManager-2.2.0/lib/layoutTemplate.inc line 152
    pagedefault->_runmodules() called at /usr/local/lib/php/siteManager-2.2.0/lib/codePlate.inc line 506
    sm_sitemanagerroot->completepage() called at /usr/local/lib/php/siteManager-2.2.0/lib/smRoot.inc line 69
    ???() called at //site_html/www/htdocs/home/catalog/index.php line 0
    

Oh, of course! It was getting there from the constructor method of the courses object being created by the acadOfferingsRenderer! Now, why didn’t I just see that? 😉 Interestingly enough, you can track the calls through our framework library right to the index.php script that was called in the first place…now that’s handy!!.

We can a few other related methods. All three are summarized below

    apd_croak       - Prints a callstack and dies.
    apd_cluck       - Prints a callstack with a warning.
    apd_callstack   - Returns a callstack as an array (for FANCY user-side formatting)
    

Some other status dumping functions (which work great inside a print_r, by the way) include:

    apd_dump_regular_resources    - Returns an array of resource types (oci8 statement, mysql link) indexed by resource number
    apd_dump_persistent_resources - Just about the same thing.
    dump_function_table           - Should be apd_dump_function table...
    override_function             - You guessed it, great for replacing php functions with "one liner" replacements
    rename_function               - Renames functions in the symbol table.  Oh, yeah.
    

Interactive Debugging

So, if you are not impressed yet…go get yourself a copy of the tcputils. Those of you with Debian or BSD probably already have them. Those of us RH users…have to pull them from here.

Once you have the tool tcplisten in your path, fire up an xterm and type:

    $ tcplisten -r localhost 7112

Or any other available port number that you wish.

Now, add the following somewhere towards the top of your source code:

    apd_set_session_trace_socket("127.0.0.1",APD_AF_INET,7112,99);

You should see it stream a bunch of stuff (if there is a lot more “running” to do” to your terminal. Nice, huh? It get’s better. This time, start up your term with the following:

    $ while tcplisten -r localhost 7112; do echo END OF SESSION...; done

and add a apd_breakpoint(1); to your php script.

You should get a rather dangerous command line into your php session. You can echo back values using apd_echo(), set variables in real time, call functions, output to the browser…all the evil things you may want to do. Just type apd_continue(1); to move your script again.

You can look at an example of using apd_breakpoint();

Just to point out, apd_echo() works in your program as well as a simple way to have your “debugging info” go to another window. This works well, but it may be easier to have a function like debugLog() that only calls apd_echo if the module is loaded. You wouldn’t want your production code blowing up when it gets to your non-apd server!

If the command line isn’t your thing, you can also try the PHP-GTK based php mole.

Cool Commands

Here are a couple of little helpers I recommend using:

    Does a standard profile on the most recent pprof dump (presuming you are in your dump directory)
      $ pprofp -u `ls -t pprof*  
      
    Generates your calltree off of the most recent pprof dump
      $ pprofp -t `ls -t pprof* | head -1 ` > calltree.txt
    
    Repeatedly opens a monitor console for your apd_set_session_trace_socket()
      $ while tcplisten -r localhost 7112; do echo END OF SESSION...; done
    

More Links

More Debuggers

This is just a sampling of the ones I bumped into…feel free to add more in the comments.

Happy Debugging!!!

Newsletter: May 16, 2003

O’Reilly User Group Program
Newsletter
May 16, 2003
 Highlights This Week:
 ----------------------------------------------------------------
 Book News
 ----------------------------------------------------------------
 -C++ in a Nutshell
 -The Complete FreeBSD, 4th Edition
 ----------------------------------------------------------------
 Upcoming Events
 ----------------------------------------------------------------
 -Tim O'Reilly at the FreeNetworks Conference in Las Vegas, NV
 --June 7-8
 -Hacks Author Event at Powell's Bookstore in Portland, OR--June 11
 -David Pogue ("Mac OS X: The Missing Manual"), MetroMac Meeting,
 SoHo Apple Store, NY--June 12
 -David Jordan ("Java Data Objects"), Barnes & Noble in Cary, NC
 --June 16th
 ----------------------------------------------------------------
 Conferences
 ----------------------------------------------------------------
 -O'Reilly Open Source Convention Early Bird Registration Ends May 23
 -Put Up an O'Reilly Open Source Convention Banner, 
 Get a Free Book
  ----------------------------------------------------------------
 News
 ----------------------------------------------------------------
 -What I Hate About Your Programming Language
 -Geeking in the Third World
 -Vote for Your Favorite Linux Book
 -How Servlet Containers Work
 -Instrumenting Your .NET Application
 -New on Safari: Mac OS X: The Missing Manual
 -Goodbye PDA, Hello iPod?
 ----------------------------------------------------------------
 News From Your Peers
 ----------------------------------------------------------------
 -Huntsville Windows NT Users Meeting, AL--May 19
 -Portland Linux User Group Meeting, Portland, OR--June 3
 -Hampton Roads Oracle Users Group,Virginia Beach, VA--June 4
 
 ================================================
 Book News
 ================================================
 Review books are available--email me for a copy.
 
 ***Please include the book order number on your requests.
 
 Let me know if you need your books by a certain date.
 Allow at least four weeks for shipping. 
 Send or email me copies of your newsletters and book reviews.
 
 Don't forget, your members get 20% off any O'Reilly book they purchase
 directly from O'Reilly. Just use code DSUG when ordering.
 http://www.oreilly.com/
 
 ***Group purchases with better discounts are available***
 Please let me know if you are interested.
 
 Press releases are available on our press page:
 http://press.oreilly.com/
 
 
 ***C++ in a Nutshell
 Order Number: 298X
 "C++ in a Nutshell" packs an enormous amount of information on C++ (and
 the many libraries used with it) in a lean quick reference that offers
 practical examples for the most important, most often used aspects of
 C++. Cross-references link related methods, classes, and other key
 features. When you're programming, you need answers quickly to
 questions about language syntax or parameters required by library
 routines. This is an ideal resource for students as well as
 professional programmers.  http://www.oreilly.com/catalog/cplsian/
 
 Chapter 4, "Statements," is available online:
 http://www.oreilly.com/catalog/cplsian/chapter/index.html
 
 ***The Complete FreeBSD, 4th Edition
 Order Number: 5164
 This new edition, covering version 5 of FreeBSD, is now available
 through O'Reilly Community Press. It is an eminently practical
 guidebook that explains not only how to get a computer up and running
 with the FreeBSD operating system, but also how to turn it into a
 highly functional and secure server that can host large numbers of
 users and disks, support remote access, and provide web service, mail
 service, and other key parts of the internet infrastructure.
 http://www.oreilly.com/catalog/cfreebsd/
 
 ===============================================
 Upcoming Events
 ===============================================
 ***Tim O'Reilly at the FreeNetworks Conference in Las Vegas, NV
 --June 7-8
 FreeNetworks.org is presenting the first annual FreeNetworks
 conference, bringing together the experts and implementers in community
 wireless networking groups from across the globe, innovators from the
 wired community and municipal networks, and the technologists designing
 the hardware for future phases of this amazing movement. Keynote
 presentations by Tim O'Reilly and Cory Doctorow. Presenters include
 representatives from BAWUG, Seattle Wireless, NoCat NYCwireless,
 Consume, Wireless Leiden, and various other community wireless
 networking efforts from around the world (including O'Reilly's "Linux
 Server Hacks" author Rob Flickenger and the O'Reilly Network's Schuyler
 Erle).
 
 FreeNetworks Conference 2003
 June 7 and 8, 2003
 Alexis Park Hotel & Resort
 375 E. Harmon Ave
 Las Vegas, NV
 http://con.freenetworks.org/
 
 
 ***Hacks Author Event at Powell's Bookstore in Portland, OR--June 11
 Rael Dornfest and Rob Flickenger, authors of O'Reilly's best-selling
 Hacks series ("Google Hacks," "Linux Server Hacks," and "Mac OS X
 Hacks"), will be at Powell's to talk about their top-rated tomes,
 answer questions, and reveal a few of the private hacks that didn't
 make the series.
 
 Powell's will be giving away a Hacks book with any O'Reilly book
 purchased, excluding Pocket References, all day June 11.
 
 Powell's Technical Bookstore
 June 11, 7pm
 33 NW Park Avenue
 Portland, OR
 http://www.powells.com/technicalbooks
 
 ***David Pogue ("Mac OS X: The Missing Manual"), MetroMac Meeting, 
 SoHo Apple, NY--June 12 
 David will unveil the "Secrets of iPhoto 2" from his upcoming book
 "iPhoto2: The Missing Manual." First come, first serve seating is
 available in the upstairs theater.
 
 June 12. 6-8pm
 Apple Store SoHo
 103 Prince Street
 New York, NY 10012
 (212) 226-3126
 http://www.apple.com/retail/soho/
 
 
 ***David Jordan ("Java Data Objects"), Barnes & Noble in Cary, NC
 --June 16th
 David will be signing copies of his book "Java Data Objects" starting
 at 7:30pm.
 
 Barnes & Noble Booksellers
 Cary II 
 760 SE Maynard 
 Cary, NC 27511 
 919-467-3866
 http://www.barnesandnoble.com
 
 
 For more events, please see:
 http://events.oreilly.com/
 
 ================================================
 Conference News
 ================================================
 ***O'Reilly Open Source Convention Early Bird Discount Ends May 23
 --Sign up now!
 User Group members who register before May 23, 2003 get a double
 discount. Use code DSUG when you register, and you'll get 20% off the
 "Early Bird" price.
 
 To register, go to:
 http://conferences.oreillynet.com/cs/os2003/create/ord_os03
 
 
 O'Reilly Open Source Convention
 Portland Marriott Downtown,
 Portland, OR
 July 7-11, 2003
 http://conferences.oreilly.com/oscon/
 
 
 ***Put Up an O'Reilly Open Source Convention Banner, Get A Free Book
 Ready for the next conference banner promotion? Here it is:
 We are looking for user groups to display our conference banners on
 their web sites. If you send me the link to your user group site with
 our O'Reilly Open Source Convention banner, I will send
 you the O'Reilly book of your choice.
 
 OSCON Conference Banners:
 http://ug.oreilly.com/banners/oscon2003/
 
 ================================================
 News From O'Reilly & Beyond
 ================================================
 ---------------------
 General News
 ---------------------
 ***What I Hate About Your Programming Language
 Choosing a programming language is rarely ever as easy as making a list
 of features and choosing the best ones. Like programming, it can be
 messy and opinionated. Every language has its own philosophy, and
 whether that fits your own mind is often a matter of taste.
 http://www.onlamp.com/pub/a/onlamp/2003/05/12/languagephilosophy.html
 
 ---------------------
 Open Source
 ---------------------
 ****Geeking in the Third World
 Geekcorps volunteers work in third world countries to help companies
 become technically competent IT businesses. Richard Koman interviews
 Geekcorps founder Ethan Zuckerman, who will be participating in
 O'Reilly's Geek Activism Summit at OSCON 2003.
 http://www.oreilly.com/pub/a/oreilly/news/ethan_0503.html
 
 O'Reilly's Open Source Convention:
 http://conferences.oreilly.com/oscon/
 
 
 ***Vote for Your Favorite Linux Book
 Cast your votes for the first Linux Business & Technology Readers'
 Choice Awards. Voting for the "Oscars of the Software Industry"
 continues until August 30. Register your vote now!
 http://www.sys-con.com/linux/readerschoice2003/
 
 ---------------------
 Java
 ---------------------
 ***How Servlet Containers Work
 Having explained how a Java web server works, Budi Kurniawan next turns
 his attention to explaining how servlet containers work. He presents
 two examples that handle simple servlets and static content.
 http://www.onjava.com/pub/a/onjava/2003/05/14/java_webserver.html
 
 ---------------------
 .NET
 ---------------------
 ***Instrumenting Your .NET Application
 As they refine the .NET story, Microsoft seems to be getting more and
 more serious about pushing into the "enterprise" space. One of the
 latest pieces of evidence of this push is the release of the Enterprise
 Instrumentation framework (EIF), a set of classes and utilities that
 work with the .NET languages to provide white-box monitoring for
 distributed applications. Mike Gunderloy shows you how to add
 instrumentation to your own .NET applications.
 http://www.ondotnet.com/pub/a/dotnet/2003/05/12/instrumenting.html
 
 ---------------------
 Mac
 ---------------------
 ***New on Safari: Mac OS X: The Missing Manual
 This best-selling Pogue Press/O'Reilly title is now available online
 through the O'Reilly Network Safari Bookshelf. If you haven't gone on
 Safari yet, try a free trial subscription.
 https://secure.safaribooksonline.com/promo.asp?code=ORA14&portal=oreilly
 &CMP=IL19183
 
 
 ***Goodbye PDA, Hello iPod?
 Many casual PDA users dumped their old handhelds when Apple first
 introduced address and calendar synch to the iPod. But for more serious
 PDA enthusiasts, that just wasn't enough. Now with the new iPods
 running firmware 2.0, notes have been added to the mix (plus a few
 other goodies). Here's a look at how the iPod could become your next
 PDA...with a 10 GB hard drive or bigger!
 http://www.macdevcenter.com/pub/a/mac/2003/05/03/ipod_pda.html
 
 
 ***The Second Coming of the Mac OS X Innovators Contest
 The second Mac OS X Innovators Contest is now open for business. Two
 categories are available this time--U.S. Residents and International.
 http://www.macdevcenter.com/pub/a/mac/developer/2003/05/08/innovators.ht
 ml
 
 Deadline for entry is Monday, June 16, 2003.
 http://www.macdevcenter.com/mac/developer/
 
 ================================================
 News From Your Peers
 ================================================
 ***Huntsville Windows NT Users Meeting, Huntsville, AL--May 19
 Shawn Travers of Microsoft will be discussing Microsoft's Server 2003
 features.  Monday, May 19th, 6 to 8pm at the Intergraph's Building 15
 Auditorium, Huntsville, AL.  http://www.huntug.org/map
 
 
 ***Portland Linux User Group Meeting, Portland, OR--June 3
 Come Join PDXLUG June 3rd, 2003, 7pm at the Fireside Lodge, located at
 1223 SE Powell Blvd, Portland, Oregon.  http://www.pdxlug.org/
 
 
 ***Hampton Roads Oracle Users Group Meeting, Virginia Beach, VA--June 4
 HROUG will be holding an evening meeting at Old Dominion University on
 June 4th at 6:30PM For meeting information contact Hazel Zamperini @
 [email protected].
 
 
 Until next time--
 
 Marsee

Newsletter: May 6, 2003

O’Reilly has sent us our first newsletter, read on for more.
Highlights This Week:
----------------------------------------------------------------
Book News
----------------------------------------------------------------
-Mac OS X Hints
-ADO.NET in a Nutshell
-Mac OS X for Java Geeks
-Java Data Objects
-Building Embedded Linux Systems
-Active Directory, 2nd Edition
----------------------------------------------------------------
Upcoming Events
----------------------------------------------------------------
-Author Juval Lowy ("Programming .NET Components"), PGHDOTNET
Pittsburgh, PA--May 21
----------------------------------------------------------------
Conferences
----------------------------------------------------------------
-Be a part of OSCON's first Hackathon July 6 & 7
-O'Reilly Mac OS X Conference Call for Participation--
Deadline is May 14
-Put Up an O'Reilly Open Source Convention Banner, 
Get a Free Book
---------------------------------------------------------------
Safari 
----------------------------------------------------------------
-"Go On Safari" winner--S. Patrick Eaton, Tokyo PC Users Group
----------------------------------------------------------------
News
----------------------------------------------------------------
-Head First: Just Bring Your Brain 
-Electronic Archaeology
-OSCON Keynotes
-Open Source and Open Standards
-Creating Richer Hyperlinks with JSP Custom Tags
-Feed Your Head at ETech 2003
-The Secrets of Strong Naming
-Apple Brings Good Karma to Online Music
-Freeware Gems for Mac OS X 
----------------------------------------------------------------
News From Your Peers
----------------------------------------------------------------
-Twin Cities PHP Users Group Meeting, St. Paul, MN--May 14
-Syracuse Area Java Users Group Meeting, Dewitt, NY--May 21

================================================
Book News
================================================
Review books are available--email me for a copy.

***Please include the book order number on your requests.

Let me know if you need your books by a certain date.
Allow at least four weeks for shipping. 
Send or email me copies of your newsletters and book reviews.

Don't forget, your members get 20% off any O'Reilly book they purchase
directly from O'Reilly. Just use code DSUG when ordering.
http://www.oreilly.com/

***Group purchases with better discounts are available***
Please let me know if you are interested.

Press releases are available on our press page:
http://press.oreilly.com/

***Mac OS X Hints (Yeah! Finally...)
Order Number: 4516
Mac OS X holds many delicious secrets--you just have to know where to
find them. This handy reference shows intermediate to advanced
aficionados of Mac OS X how to adjust the desktop, tweak applications,
reconfigure the system, and even fine-tune the software in Mac OS X's
Unix-based core. It also shows how to handle numerous, complex system
administration tasks. Presented in an easy-to-follow, cross-referenced
format, "Mac OS X Hints" will help you get the most out of Mac OS X
10.2.  http://www.oreilly.com/catalog/macxhints/


***ADO.NET in a Nutshell
Order Number: 3617
"ADO.NET in a Nutshell" is the most complete and concise source of
ADO.NET information available. Besides being a valuable reference, this
book covers a variety of issues that programmers face when developing
web applications or web services that rely on database access. Using
C#, the book presents real-world, practical examples that will help you
put ADO.NET to work immediately. Included on CD-ROM is a Visual Studio
.NET add-in that integrates the entire reference directly into your
help files.  
http://www.oreilly.com/catalog/adonetian/

Chapter 12,"DataViews and Data Binding," is available online:
http://www.oreilly.com/catalog/adonetian/chapter/index.html


***Mac OS X for Java Geeks
Order Number: 4001
"Mac OS X for Java Geeks," written specifically for Java developers,
gives a complete, detailed look at Mac OS X. Whether you're a Java
newbie, working your way through Java Swing and classpath issues, or a
Java guru, comfortable with digital media, reflection, and J2EE, this
book will teach you how to get around on Mac OS X. You'll also get the
latest information on how to build applications that run seamlessly,
and identically, on Windows, Linux, Unix, and the Mac.
http://www.oreilly.com/catalog/macxjvgks/

Chapter 10, "QuickTime for Java," is available online:
http://www.oreilly.com/catalog/macxjvgks/chapter/index.html


***Java Data Objects
Order Number: 2769
"Java Data Objects" is the definitive work on the JDO API. It gives you
a thorough introduction to JDO and shows you how to: make classes
persistent and how JDO maps persistent classes to the database;
configure JDO at runtime; perform transactions; and make queries. More
advanced chapters cover optional features such as nontransactional
access and optimistic transactions. The book concludes by discussing
the use of JDO in web applications and J2EE environments.
http://www.oreilly.com/catalog/jvadtaobj/

Chapter 1, "An Initial Tour," is available online:
http://www.oreilly.com/catalog/jvadtaobj/chapter/index.html


***Building Embedded Linux Systems
Order Number: 222X
"Building Embedded Linux Systems" shows you how to design and build
your own embedded systems using Linux as the kernel, and freely
available open source tools as the framework. The book gradually
introduces readers to the intricacies of embedded Linux with detailed
information and examples that describe how Linux is actually put on an
embedded device. You'll learn the strengths and weaknesses of Linux as
an embedded OS, as well as what licensing issues are involved.
http://www.oreilly.com/catalog/belinuxsys/

Chapter 5, "Kernel Considerations," is available online:
http://www.oreilly.com/catalog/belinuxsys/chapter/index.html


***Active Directory, 2nd Edition 
Order Number: 4664
"Active Directory, 2nd Edition" gives a clear, detailed look at Active
Directory for both Windows 2000 and Windows Server 2003. You'll become
familiar with the Lightweight Directory Access Protocol (LDAP),
multi-master replication, Domain Name System (DNS), Group Policy, and
the Active Directory Schema, among many other topics. This book will
guide you through the maze of concepts, design issues, and scripting
options, enabling you to get the most out of your deployment.
http://www.oreilly.com/catalog/actdir2/

Chapter 14, "Upgrading to Windows Server 2003," is is available
online:  
http://www.oreilly.com/catalog/actdir2/chapter/index.html

===============================================
Upcoming Events
===============================================
***Author Juval Lowy ("Programming .NET Components"), PGHDOTNET 
Pittsburgh, PA--May 21
Juval will be presenting ".NET Remoting" to the Pittsburgh .NET User
Group.

For more info and to RSVP:
http://www.pghdotnet.org/

May 21st from 6-8pm
Pittsburgh Technology Council
2000 Technology Drive
Pittsburgh, PA 15219
http://www.pghtech.org/contact/directions.html

For more events, please see:
http://events.oreilly.com/

================================================
Conference News
================================================
***Be a part of OSCON's first Hackathon July 6 & 7
Pick an open source project, gather a group of hackers, and descend on
the Hackathon. We'll provide the room, bandwidth, tables, chairs, and
white boards--you provide the code. Space is limited. If you are
interested in participating, send email to [email protected]
by June 1, 2003.

O'Reilly Open Source Convention
Portland Marriott Downtown,
Portland, OR
July 7-11, 2003
http://conferences.oreilly.com/oscon/


Early Bird Discount--
User Group members who register before May 23, 2003 get a double
discount. Use code DSUG when you register, and you'll get 20% off the
"Early Bird" price.

To register, go to:
http://conferences.oreillynet.com/cs/os2003/create/ord_os03


***O'Reilly Mac OS X Conference Call for Participation--Deadline is May 14
System administrators, developers, strategists, technical staff, and
power users are invited to submit proposals to lead tutorial and
conference sessions at the second annual O'Reilly Mac OS X Conference.
Suggested topics include: Scripting Genius, Amazing Applications,
Ingenious Hacks, and SysAdmin Mac Style, to name a few.
http://conferences.oreilly.com/macosxcon/

The submission deadline for proposals is May 14, 2003:
http://conferences.oreillynet.com/cs/macosx2003/create/e_sess


***Put Up an O'Reilly Open Source Convention Banner, Get A Free Book
Ready for the next conference banner promotion? Here it is:  We are
looking for user groups to display our conference banners on their web
sites. If you send me the link to your user group site with our
O'Reilly Open Source Convention banner, I will send you the O'Reilly
book of your choice.

OSCON Conference Banners:
http://ug.oreilly.com/banners/oscon2003/

================================================
Safari News
================================================
***"Go On Safari" Weekly Winner--S. Patrick Eaton, Tokyo PC Users Group
"Shipping books from overseas has always been time-consuming and
costly. Buying books locally is costly, too, and often means putting up
with limited selections, especially in the area of technical
books--which are the kind I crave most....Fortunately, [this isn't] a
problem any more. I've just signed up for my own Safari Bookshelf."

Your group can also participate in this introductory program just for
user group members. To "Go on Safari," any of your members who sign up
for our Safari 14-day free trial send comments on their experiences, or
tips and tricks for how they used Safari  (it only needs to be 2
sentences long, but it may be longer) to [email protected].

Every week someone will be chosen from the tips or comments submitted
to receive fun stuff from O'Reilly (T-shirts, book bags, or other
surprises). If a member of your user group is selected, your group
receives free gifts, too. Whatever the individual member receives, your
UG will get one, too, to give away at your next meeting, or use however
you see fit. Recipients--and their comments--will be announced in the
User Group Newsletter.

**Please use this special UG URL to sign up for the 14-day trial**
http://www.oreilly.com/safari/ug

For more information on Safari:
http://safari.oreilly.com/

================================================
News From O'Reilly & Beyond
================================================
---------------------
General News
---------------------
***Head First: Just Bring Your Brain
Wacky themes, far-out images, and strange examples--O'Reilly's new Head
First book series helps you learn with stories, games, and pictures.
Learning a new technology doesn't have to be boring; see for yourself
with O'Reilly's upcoming "Head First Java."
http://headfirst.oreilly.com/

Head First Java (Out this month)
Order Number: 4656
http://www.oreilly.com/catalog/hfjava/


***Electronic Archaeology
It takes time to make a good mess. Programs start out simple, but then
the code evolves (or devolves) over the years. Different people work on
it, and it appears many of them knew very little about programming. The
result for professional programmers is having to deal with badly
designed, badly implemented, uncommented, incomprehensible blobs. The
art of digging through ancient, muddled code is called "electronic
archaeology," and this article, by Steve Oualline, author of "Practical
C++ Programming, 2nd Edition," discusses some of the tools you can use
to make your code "digs" easier.
http://www.oreillynet.com/pub/a/network/2003/04/29/steveoaulline.html

Practical C++ Programming, 2nd Edition
Order Number: 4192
http://www.oreilly.com/catalog/cplus2/


***Feed Your Head at ETech 2003
A week in Santa Clara for the O'Reilly Emerging Technology Conference
provided attendees with lots to chew on. Daniel Steinberg gives an
inside look at the people and the topics that helped make this such a
satisfying event.
http://www.openp2p.com/pub/a/p2p/2003/05/01/etech.html

---------------------
Open Source
---------------------
***OSCON Keynotes
Nathan Torkington: "I've had people asking me what's up with OSCON this
year--is anything interesting happening or can they skip it and watch
'Alias' reruns instead. I can't make your decision for you (the
relative attractiveness of the Alias lady and Larry Wall is something
I'll leave to you to weigh) but I can definitely talk a little about
what I'm jazzed about." http://www.onlamp.com/pub/wlg/3151

***Open Source and Open Standards
Open source means open code. It usually also means open standards. Are
they really so tightly intertwined? Which is more important to openness
in technology? Peter Saint-Andr explores these thoughts.
http://www.onlamp.com/pub/a/onlamp/2003/04/29/openstandardsopensource.html

---------------------
Java
---------------------
***Creating Richer Hyperlinks with JSP Custom Tags
Gone are the days where one destination per link was enough. With
mirroring, localization, and internationalization, your readers might
want the choice of several different resources for any given link.
Until XLink and XPointer are well-supported in browsers and authoring
tools, most alternatives are clumsy. Amit Goel demonstrates a better
approach by creating a custom JSP tag to control a dynamic menu of
destination links.
http://www.onjava.com/pub/a/onjava/2003/04/30/jsp_hyperlinks.html

---------------------
.NET
---------------------
***The Secrets of Strong Naming
If you've been working with .NET for any length of time, you've
probably run across the concept of a strong name. No, that doesn't mean
that your assemblies should have names like MyCompany.Gorilla.Biceps.
The strength of a strong name lies in the protection that it offers
your assemblies. The .NET Framework uses strong names to identify
assemblies and to protect them from tampering. In this article, Mike
Gunderloy shows you how strong names are constructed and demonstrates
the mechanics of working with strong names in .NET.
http://www.ondotnet.com/pub/a/dotnet/2003/04/28/strongnaming.html

---------------------
Mac
---------------------
***Apple Brings Good Karma to Online Music
At a much anticipated media event in San Francisco, Steve Jobs
announced Apple's new online music service, an updated version of
iTunes and third-generation iPods. Here are the details complete with
audio clips and photos from the presentation.
http://www.oreillynet.com/pub/q/all_mac_articles


***Freeware Gems for Mac OS X
Here's a collection of lesser-known freeware gems available for Mac OS
X. We're talking about neat little apps that you might not have heard
of, but that can do the job just as well as better-known (and much more
expensive) varieties without you having to pay a penny for them.
http://www.macdevcenter.com/pub/a/mac/2003/04/25/freeware.html

================================================
News From Your Peers
================================================
***Twin Cities PHP Users Group Meeting, St. Paul, MN--May 14
This meeting will feature Steve Lime, creator of Mapserver giving an
introduction to using scripting languages like PHP to create dynamic
web based spatial reports (otherwise known as maps)

May 14, 7:00pm
Offices of Minnesota Public Radio
45 East Seventh Street
St. Paul, MN 55101

For more information and directions:
http://tcphp.org


***Syracuse Area Java Users Group Meeting, Dewitt, NY--May 21
This meeting will feature "Ant: Building Mountains or Mole Hills." They
will review the use of Ant and provide examples of enterprise level
builds (JSP, Servlet, EJB, etc) usually not found in the current
literature.

May 21, 6:00pm
Partners In Health Systems
5789 Widewaters Parkway--1st Floor
Dewitt, NY 13214

Contact Bob Krause at [email protected] if you plan on attending or
need more information.


Until next time--

Marsee

KC PUG to partner with the O’reilly User Group Program

In an effort to get more exposure, door prises and some extra information, the PHP User Group of Kansas City has been submitted to the O’Reilly & Associates User Group program. I think we are still awaiting “final approval” but as we have been meeting for quite some time now…well, I’ll let you know when I hear anything. For now, I’ve attached an email detailing some of the benefits once we are “approved.”
Subject:  O'Reilly User Group Registration
Date:     28 Apr 2003 07:48:53 -0700	

Thanks for registering for the O'Reilly User Group Program. Your
application has been submitted for approval.

Explanation of program benefits:

Review copies:
O'Reilly offers free review copies of our books to qualified user
groups.  As the group contact, you may request a free review copy for
your newsletter or web site. Requests for review copies MUST be
submitted by you, as the contact of your group. If you wish for the
review copy to be shipped to someone other than yourself, please supply
the name, address and phone number of that person for shipment. Once a
review of a book has been written, please send us a copy.

Discounts:
Your group members are entitled to a 20% discount on O'Reilly products
purchased directly from us. Information for placing an order is
provided on the discount flyers that will be shipped to you, upon
acceptance to the program. Your members are also entitled to a 20%
discount on O'Reilly conferences and tutorials. Other special discount
offers may also be forwarded to your group from time to time.

Other benefits:
In addition, we regularly donate books and other promotional items for
raffles or auctions to help your group raise money, or for meeting door
prizes. On a quarterly basis, we'll send our latest catalog. Some of
our authors are willing to speak at user group meetings--let us know if
you are interested and well do what we can to help you arrange
speakers.

We'll also send you links to articles, tips, and news from the O'Reilly
web site: www.oreilly.com and from the O'Reilly Network:
www.oreillynet.com when we think the topics may interest you.

Following verification of your registration information, we'll send
your group a "Welcome Package" which includes an O'Reilly gift, 20%
discount flyers, and our latest catalog. Please allow at least 6 weeks
for delivery.

What you can do for O'Reilly (not required):
    *Post an O'Reilly User Group Program banner to your web site, which
you can find at: http://ug.oreilly.com/banners/ Please have the banner
link back to www.oreilly.com.
    *If you don't have a web site, but you do have a newsletter, please
print our sponsorship information in your newsletter. We can provide
logo art upon request.
    *Encourage your members to review our books and post the reviews on
your site or newsletter--making sure to notify me when the reviews are
available.  If you don't have a newsletter, please provide information
to your group about O'Reilly products and UG Program benefits to your
group email list.

Taking the step from personal to distributed

I keep creating scripts that other people want to use… In creating them, I basically did whatever I needed to to bend them into shape to do what I wanted… In order to distribute them to others, I pretty much have to set up everything myself… Obviously, this creates problems – even people who know me have a hard time giving me root access to their mysql db and such…

So what I’d like to see is a discussion of guidelines on how to package your php/mysql solutions for distribution so that it’s easier on the other end to get them up and running.

Part of this would be proper coding and commenting to begin with, I’m sure… But scrubbing existing code is a part of it as well. Are there any helpful functions, code bits, etc that ease the process? Any other helpful hints on how to accomplish this?

April Meeting – PHPReports

This month we will about a little class for generating reports using php. If you are really interested in new and exciting ways to separate your data layer from your presentation layer…read on.

I was a bit pressed for time, so most of this content was taken either from the README or the phpreports site. The readme really is an excellent tour of the system, so if you are interested in how to use PHPReports, I would highly recommend you read it. Now, with that out of the way…

Requirements

You will need PHP compiled with XML/XSLT support. The PHPReports author uses the Sablotron libs in his work and examples.

Hello World

The PHPReports version of the classic Hello World, would be a simple table of database information. Lets take a look at the PHPReports Simple Sample before we get to far.

Document Structure

First off, we need to talk terminology. The author defines three key divisions or sections of a report:

  • The Document Layer
  • The Page Layer
  • The Group Layer

The author describes these best:

    You just have one document layer, one page layer (you can have a lot of pages, but just one page layer to configure) and some group layers.

    All these layers collect information about the data on your report, like the number of lines, statistics about the fields and so on.
    The document layer stores ALL these statistics, and stores it till the report end.

    The page layer stores it till the page end, and reset it there.

    The group layer stores it till the end of group, (where group is a set of data defined by a break expression, which could be any kind of field contained on your data set.)

    So, to visualize it in ascii art, we might use something like this:

    
        +----------------------------------+
        | DOCUMENT_LAYER                   |
        +----------------------------------+
        | HEADER                           |
        |                                  |
        | +------------------------------+ |
        | | PAGE_LAYER                   | |
        | +------------------------------+ |
        | | HEADER                       | |
        | |                              | |
        | | +--------------------------+ | |
        | | | GROUP LAYER              | | |
        | | | break expression A       | | |
        | | +--------------------------+ | |
        | | | HEADER                   | | |
        | | | FIELDS                   | | |
        | | |                          | | |
        | | | +----------------------+ | | |
        | | | | GROUP LAYER          | | | |
        | | | | break expression A,B | | | |
        | | | +----------------------+ | | |
        | | | | HEADER               | | | |
        | | | | FIELDS               | | | |
        | | | | FOOTER               | | | |
        | | | +----------------------+ | | |
        | | | FOOTER                   | | |
        | | |                          | | |
        | | +--------------------------+ | |
        | |                              | |
        | | FOOTER                       | |
        | +------------------------------+ |
        |                                  |
        | FOOTER                           |
        +----------------------------------+
    
    

    Or, if you prefer something a bit less abstract:

    
        +---------------------------------------+----+
        | John Doe Enterprises                  |////+--- document layer
        | Sales Report                          |////|
        +------+--------------------------------+----+
        | city | <city goes here>               |\\\\|
        +------+-+------+-------------+---------+\\\\|
        | id   | name   | product     | $       |\\\\|
        +------+--------+-------------+---------+\\\\+--- group layer
        | <id> | =name= | <product>   | <value> |\\\\|
        +------+--------+-------------+---------+\\\\|
        |                       total | <total> |\\\\|
        +-----------------------------+---------+----+
        |                  page total | <total> |////+--- page layer
        +-----------------------------+---------+----+
        |                report total | <total> |\\\\+--- document layer (again)
        +-----------------------------+---------+----+
    
    

    So what does my php script look like? It’s Massive right??

    
        include 'PHPReportMaker.php';
        $sql  = "select ID,NAME,CITY,PRODUCT,VALUE from SalesLog order by ID";
        $parm = Array();
        makeReport( "sales.xml", "PHPReport.xsl", "user", "mypass", 
                "mydb", "mysql", $sql, $parm );
    

    Or…If you prefer the “cleaner” OO form:

    
    <?php
        include 'PHPReportMaker.php';
        $sql  = "select ID,NAME,CITY,PRODUCT,VALUE from SalesLog order by ID";
        $oRpt = new PHPReportMaker();
    
        $oRpt->setXML("sales.xml");
        $oRpt->setUser("user");
        $oRpt->setPassword("mypass");
        $oRpt->setConnection("mydb");
        $oRpt->setDatabaseInterface("mysql");
        $oRpt->setSQL($sql);
        $oRpt->run();
    ?>
    
    

    sales.xml – The format spec for our report

    You know that that would just be too easy, right. Do you see the “sales.xml” string above? That points to an xml file that contains the format spec for our report. Think of it as a template for our data.

    
    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <REPORT>
       <TITLE>Sales eport</TITLE>
      <BACKGROUND_COLOR>#FFFFFF</BACKGROUND_COLOR>
       <PAGE BORDER="1" SIZE="25" CELLSPACING="0" CELLPADDING="5" WIDTH="500">
          <HEADER>
             <ROW>
                <COL COLSPAN="5">John Doe Enterprises</COL>
             </ROW>
             <ROW>
                <COL COLSPAN="5">Sales Report</COL>
             </ROW>
          </HEADER>
          <FOOTER>
             <ROW>
                <COL ALIGN="RIGHT" COLSPAN="4">page total</COL>
                <COL ALIGN="LEFT" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
             </ROW>
          </FOOTER>
       </PAGE>
       <GROUPS>
          <GROUP NAME="maingroup">
             <FIELDS>
                <ROW>
                   <COL>id</COL>
                   <COL>name</COL>
                   <COL>city</COL>
                   <COL>product</COL>
                   <COL>value</COL>
                </ROW>
             </FIELDS>
          </GROUP>
       </GROUPS>
    </REPORT>
    

    This xml might show us a report that looks a lot like the following:

    Where’s the REAL code?? Some more complete examples

    There is a how-to example on the phpreports website that illustrates this topic. It also includes the complete XML file for generating the report.

    There are a host of other Samples available on their site.
    Be sure to check out their Super Swanky Report as well as the Debugging section. Yes, it has it’s own debugging helper.

Call for Speakers

Is there a php topic that you have been just itching to learn? Maybe something that you think would be of great help to the rest of our PHP loving community? Speaking at the KCPUG is a great way to make friends and gain experience. The “usual” speakers are just swamped this month, so this would be a great time to volunteer. 😉

I’ll even buy a can of soda (or bottle of water) from the machine for the brave soul who steps up to the plate! If you are serious about speaking, please comment to this thread by Apr 21st.

Thanks!!

EDITED: 2003-04-23 dholmes, Ok…So I whipped up a little something for this month. But the offer for a can of soda for just a little effort still stands. 😉 Feel free to “Sign-up” with your comments below. If you don’t want to speak but have an idea, please offer those too. Half the work is finding something to talk about. 🙂

SOAP and PHP; now on phppatterns

Like him or not (I personally do), Harry Fuecks always has pleanty of great info on his site: phppatterns.com. There is no exception this week. He has just posted a flury of articles on using php to write SOAP/WSDL clients, SOAP servers and all kinds of other sudsy goodness. Read more for the direct links, or just go to his site: phppatterns.com
Posted in PHP

Mixed output and timing

Right, so I learned to code mixed html/php the sloppy way, switching back and forth whenever the mood struck. Lately, I’ve been realizing what a pain it is to figure out what’s where when something needs to
change…. so I switched to just putting all my output into a variable, then outputting it in a pesudo-template at the end of the script.
I’ve started working with larger datasets, so I added a timer function to display the time it took to generate each page in the footer…. I ran my old page a few times, and saw consisted 4+ second generation times. I changed it to the pseudo-template, and I’m getting consistent .2 second times.

I also read of a difference in using
“stuff $php_variable stuff”, which is slower than
“stuff ” . $php_variable . ” stuff”, so I changed that where
appropriate as well. Additionally, ‘stuff’ is also faster, but by a neglible amount.

Here’s the old code:
[code]
while ($myrow = mysql_fetch_array($result)) {
if (mysql_errno() != 0) {
echo “Error ” . mysql_errno() .”

“;
} else { // end if (mysql_errno() != 0)
?>


“;
} else { // end if (mysql_errno() != 0)
$out .= “

“;
$out .= ”

” . $myrow[“id”] . ”
“;
$out .= ”

” . $myrow[“title”] . ”
“;
$out .= ”

” . $myrow[“artist”] . ”
“;
$out .= ”

” . $myrow[“bpm”] . ”
“;
$out .= ”

” . $myrow[“genre”] . ”
“;
$out .= ”

” . $myrow[“stuff”] . ”
“;
$out .= ”

“;
} // end else
} // end while ($myrow = mysql_fetch_array($result))
[/code]
This was for about 425 rows, I believe.

I had no idea it made THAT much of a difference… Guess I’ll be using that on everything now… If not switching over to SMARTY or some other true templating system.

Posted in PHP

Free PHP IDE w/ Debugger

There is a new free PHP IDE available from a company called Maguma. It is for windows 98, Me, 2000, and XP. If you download the complete version it installs PHP 4.3 on your machine and it adds debugging functionality to the IDE. Sounds pretty nifty. I downloaded it the other day on my home computer but haven’t really tried it out yet. If anyone is looking for a free PHP development program with advanced functionality you might want to try it and let us know what you think.