www.phparch.com AUGUST 2003 The Magazine For PHP Professionals Case studies in Case studies in Client/Server ApplicationsClient/Server Applications VOLUME II - ISSUE 8 Transforming XML to PDF Transforming XML to PDF with the help of LaTeXwith the help of LaTeX Embedding Assembler in PHPEmbedding Assembler in PHP Take your PHP to new lowsTake your PHP to new lows php | Cruise March 1 st - March 5 th 2004 See inside for details Get Ready For Maintenance Maintenance from the Outsetfrom the Outset Building a monitoring system Building a monitoring system into your scriptsinto your scripts Plus: Tips & Tricks, Product Reviews and much more . An Introduction to MingAn Introduction to Ming Create amazing Flash Create amazing Flash applications on-the-flyapplications on-the-fly An Introduction to cURLAn Introduction to cURL Discover the ins and outs Discover the ins and outs of this indispensable toolof this indispensable tool *By signing this order form, you agree that we will charge your account in Canadian dollars for the “CAD” amounts indicated above. Because of fluctuations in the exchange rates, the actual amount charged in your currency on your credit card statement may vary slightly. †Limited time offer expires August 31st, 2003. Choose a Subscription type: Canada/USA $ 81.59 $67.99 CAD ($59.99 $49.99 US*) International Surface $108.99 $94.99 CAD ($79.99 $69.99 US*) International Air $122.99 $108.99 CAD ($89.99 $79.99 US*) Your charge will appear under the name “Marco Tabini & Associates, Inc.” The first issue of your subscription will be mailed to you in September, 2003. Please allow up to 6 weeks for your subscription to be established. *US Pricing is approximate and for illustration purposes only. php|architect Subscription Dept. P.O. Box 3342 Markham, ON L3R 9Z4 Canada Name: Address: City: State/Province: ZIP/Postal Code: Country: Payment type: VISA Mastercard American Express Credit Card Number: Expiration Date: E-mail address: Phone Number: Buy now and save $10 off the price of any subscription† Visit: http://www.phparch.com/print for more information or to subscribe online. Signature: Date: To subscribe via snail mail - please detach this form, fill it out and mail to the address above or fax to +1-416-630-5057 php|architect The Magazine For PHP Professionals Existing subscribers can upgrade to the Print edition and save! Login to your account for more details. NEW! NEW! Signup now and save $100.00! Hurry, space is limited. Visit us at www.phparch.com/cruise for more details. php | Cruise March 1 st - March 5 th 2004 Andrei Zmievski - Andrei's Regex Clinic , James Cox - XML for the Masses , Wez Furlong - Extending PHP , Stuart Herbert - Safe and Advanced Error Handling in PHP5, Peter James - mod_rewrite: From Zero to Hero, George Schlossnagle - Profiling PHP, Ilia Alshanetsky - Programming Web Services, John Coggeshall - Mastering PDFLib, Jason Sweat - Data Caching Techniques <? ?> We’ve got you covered, from port to sockets. Port Canaveral • Coco Cay • Nassau Plus: Stream socket programming, debugging techniques, writing high-performance code, data mining, PHP 101, safe and advanced error handling in PHP5, programming smarty, and much, much more! TABLE OF CONTENTS 4 August 2003 · PHP Architect · www.phparch.com II NN DD EE XX Departments php|architect Features 10 Transforming XML to PDF with LaTeX Stephan Schmidt 16 Ming & PHP Seth Wilson 33 Sockets: Part 2 Eugene Otto 41 Grokking cURL Peter James 48 Maintenance from The Outset Graeme Foster 57 Embedding Assembler in PHP Igor Gorelik 5 Editorial 7 What’s New! 26 Granted! Announcing the winners of the 2003 php|architect Grant Program 29 Datanamic DeZign for Databases 3 Peter James 65 Tips & Tricks John W. Holmes 69 Bits & Pieces 71 e x i t ( 0 ) ; Expect More From php|a Marco Tabini TABLE OF CONTENTS EDITORIAL 5 August 2003 · PHP Architect · www.phparch.com EE DD II TT OO RR II AA LL RR AA NN TT SS php|architect Volume II - Issue 8 August, 2003 Publisher Marco Tabini Editor-in-Chief Brian K. Jones brian@phpar ch.com Editorial Team Arbi Arzoumani Brian Jones Eddie Peloke Peter James Marco Tabini Graphics & Layout Arbi Arzoumani, William Martin Managing Editor Emanuela Corso Authors Greame Foster, Igor Gorelik, Peter James, Eugene Otto, Stephan Schmidt, Marco Tabini, Seth Wilson php|architect (ISSN 1705-1142) is published twelve times a year by Marco Tabini & Associates, Inc., P.O. Box. 3342, Markham, ON L3R 6G6, Canada. Although all possible care has been placed in assuring the accuracy of the contents of this magazine, including all associated source code, listings and figures, the publisher assumes no responsibilities with regards of use of the information contained herein or in all associated material. Contact Information: General mailbox: info@phparch.com Editorial: editors@phparch.com Subscriptions: subs@phparch.com Sales & advertising: sales@phparch.com Technical support: support@phparch.com Copyright © 2002-2003 Marco Tabini & Associates, Inc. — All Rights Reserved I could not be happier right now. As I sit here at my laptop, writing this editorial, by my side sits a glass of beer that I made from scratch, not quite a month ago. I’m inspired by the similarities that exist between the evolution of php|architect as a powerhouse publication and de facto standard source of PHP knowledge, and the creation of what is now a simple glass of lovely ale. I brew with real grain and real hops. None of this ‘just add water’ stuff. I’ve never done it, and I won’t. I suppose it’s fine if you just want a ‘quick and dirty’ beer. However, I have an overwhelming feeling that my integrity as a brewer would be sac- rificed for ‘ease’ (I call it ‘laziness’), and it doesn’t sit well with me. I want honest beer. I want to know how the wort was produced, and where it came from. Indeed, I want to be intimately associ- ated with the very essence of the finished product. For better, or for worse. I found this same spirit in the publisher of php|architect, who I’ve now come to know as both a good friend and close business associate, Marco Tabini. Marco understood my leanings toward things that were, for lack of a better term, ‘organic’ or ‘untainted’. I wanted material written by doers. I shunned several articles by profession- al writers whose writing lacked the spirit that we’ve by now become accustomed to at php|architect; the spirit of someone who has fought and lost battles on their way to great dis- coveries using PHP. Other writers, in comparison, appear to have ‘just added water’. We’ve made it a goal to avoid such articles. Of course, it is the ‘road less traveled’, but we feel it has made all the difference, and you’ve let us know that we’re right. Of course, brewing from scratch comes with its headaches. Brewing from scratch means more steps are involved, the materials are handled and transferred more often, and more opportunities exist for molds and bacterias to be introduced into the beer. While I’ve so far been able to avoid that, and produce very drinkable beer, it is not without its flaws. The one I’m drinking now took on a bit of a ‘chill haze’ after being bottled, for example; a minor problem that doesn’t affect anything but the aesthetic qualities of the beer. As I continue to brew and master the craft, I’ll inevitably fix the ‘chill haze’ problem, while introducing others. Eventually, it all works out, and you achieve ‘excel- lent beer’. EDITORIAL 6 August 2003 · PHP Architect · www.phparch.com Such is the case with this magazine as well. We’re not perfect. We haven’t ever claimed to be perfect, and as a team, I don’t think any of us could ever foresee a day when there isn’t at least the slightest bit of ‘haze’. However, it is the atti- tude of this team that as long as there is not per- fection, there is work to be done, and so we’re constantly busy, if not with fingers to the key- board, then with developing ideas or analyzing weaknesses. It is this attitude, and the fact that it permeates every digital thread of the publication, that will earn us whatever critical acclaim may await us. Finally, beer and brewing is a learning process. I was fortunate enough that my buddy Matt was an already experienced brewer without a convenient location to brew, and I was a homeowner with a large back yard and a willingness to learn. Matt and I have known each other since childhood, and we work well together. We understand each other and relate to each other better than most other people we know. This makes for a great working relationship, partially because we grew out of the ‘polite friendship’ stage somewhere around age 14. We constantly question and debate. Our beer thus far has been better for it. This type of work- ing relationship is invaluable in creating anything of any quality. In striving for quality of material in php|archi- tect, anyone who has written for our editorial team will note that I take a decidedly different approach. The approach is largely the brainchild of Marco and I, who have somehow been able to achieve a vigorous and successful working rela- tionship. Constantly questioning and debating each other, we’re always playing ‘devil’s advocate’ to insure that, in the end, we’ve done right by all parties involved. In the process we’ve learned what makes this monster we’ve created tick, and how to channel our efforts to add even more value to our readership. Our ability to come to a ‘meet- ing of the minds’ on all aspects of the publication has brought us not only to where we are now, but will influence the direction of the publication in the future – for better, or for worse. In reality, at the end of the day, it’s our ability to tell each other that our ideas completely suck that has made all the difference! But there is another ingredient in our recipe at php|architect. It’s the ‘recognition’ phase. Recognition of a person’s ‘highest and best use’. We seek people to join our team who we feel we can work with, and we eventually move everyone into a position where their interests and skills are put to work to produce the best ‘stuff’ that they can. As I’ve mentioned from the very beginning, editorial work is not my highest and best use. No matter how much I love editing and the editorial process, the reality is that a) I’m not a hardcore coder, and b) I’m not a hardcore editor! It is with these words that I am proud to pass the Editor in Chief torch to the very capable Peter James. Peter has accomplished much in his rela- tively short time as Senior Editor at php|architect, affecting both the outward appearance of the magazine, as well as the backend procedures for coordinating the editorial process. All by his own initiative, and all without a thought for anything but the good of the publication. Furthermore, as if this weren’t enough, he still constantly asks for more responsibility, and a greater role in the mag- azine’s creation. Finally, I came to the conclusion that the only way for Pete to do anything more was to take my job, which would allow me to be applied to my highest and best use as well. So from now on, it will be Pete’s job to try hard to give you all a reason to read the editorial column that I’m still convinced is a pretentious waste of paper (be it digital or ‘dead tree’ in form). I’ll not be far, mind you! I’m taking on a new role that will also produce some really cool and excit- ing new (but as yet unmentionable) ‘stuff’ in the not too distant future. I’m excited at the opportu- nity, though I’ll always make myself available on those sleepless nights when Pete can’t get some ‘damned Linux code’ to validate or something. I wish Pete a lot of luck, and thank him for the hard work he’s done, along with the rest of the production crew who have helped php|architect become what we are today, and what we will be tomorrow. I also thank all of the readers for the feedback and guidance along the way. .until we meet again . brian. 7 PHP 4.3.3 RC3 PHP.net announced the release of PHP 4.3.2 release candidate 3. “This should be the last release candidate prior to the final 4.3.3 release. Please test this release as much as possible, so that any remain- ing issues can be uncovered and resolved.” Bug fixes include: • escapeshellcmd() can now handle quoted arguments • exit code lost when exit() called from register_shutdown_function() • methods misidentified as constructors • and much more . Visit php.net to download or view the change log. Apache 2.0.47 The Apache Software Foundation and the Apache HTTP Server Project announce the tenth public release of the Apache 2.0 HTTP Server. This is a security, bug fix and minor upgrade release. Due to security issues, any sites using Apache 2 versions prior to Apache 2.0.47 should upgrade to Apache 2.0.47. Security issues: a. Fixed a bug in the handling of accept errors by the prefork MPM when handling accept errors, which could allow a denial of service attack if multiple listeners are configured. b. Fixed a bug in the optional renegotiation code in mod_ssl which could cause cipher suite restrictions to be ignored if optional renegotiation is enabled. c. Fix of denial of service attack in mod_proxy’s handling of DNS results. New features: Added support for a “prefer-language” environment variable to mod_negotiation” To download, visit Apache.org ionCube and the Cerberus Encoder ionCube.com announced the release of the ionCube 3.0. The ionCube standalone PHP encoder is a high perform- ance encoding solution for PHP, offering encoding of com- piled code to deliver the maximum security and run-time performance for encoded file, and features to allow easy integration into build and release systems, and also web- sites for just-in-time software delivery. New Version 3.0 advantages: a. Customizing of Loader event messages b. Restricting encoded files to only cooperate with other encoded files that have certain ‘properties’. c. Improved encoding performance. In addition to Version 3.0, Ioncube has released the Cerberus Encoder. This is the same as the full featured encoder, but adds the ability to restrict files to a MAC address. For more information, visit ionCube.com . NN EE WW SS TT UU FF FF August 2003 · PHP Architect · www.phparch.com WWhhaatt’’ss NNeeww!! 3 php|Cruise ‘04 10 Transforming XML to PDF with LaTeX 16 Ming & PHP 33 Sockets: Part 2 41 Grokking cURL 48 Maintenance from The Outset 57 Embedding Assembler in PHP 7 What’s New! 26 Granted! 29 Datanamic DeZign for Databases 3 65 Tips & Tricks 69 Bits & Pieces 71 e x i t ( 0 ) ; NEW STUFF PHPNuke 6.7 PHPNuke.org announced the release of version 6.7. PHPNuke is a PHP based content management system. This newest version fixes XSS and other vulnerabilities and security bugs like path disclosure, and adds associat- ed topics to the News module. There are many cosmetic changes and minor bugs fixed, and the Update folder was reorganized. You can get more information or download from PHPNuke.org . PHPEdit 0.7.1.131 PHPEdit.net announced the release of PHPEdit 0.7.1.131. It’s still a development version but takes one step further to the stable release. It contains proposal #2, #3 and #7 of the PHPEdit Community. PHPEdit invites all users to report problems or tweaks in 0.7.1.131 to the PHPEdit Community. PHPEdit also asks all users to vote for requests they want to be in the next release to the Community. Visit PHPEdit.net to download. patUser 2.1.2 and 2.20 Beta PHP Application Tools announced the release of patUser 2.1.2 and 2.20 Beta New in this version: bugs, notices and warnings removed. Warning: this is the last version of patUser sup- porting patDbc, as we are switching to PEAR::DB. Version 2.2.0 is the new branch supporting PEAR:DB - but keep in mind that it is still BETA! If you are willing to test it, feel free to send your bug reports to gERD directly. “ For more information or to download, visit PHP-T ools.de. Databases MySQL and PostgreSQL both announced new releases this month. PostgreSQL 7.3.4 PostgreSQL.org announced the release of their latest version 7.3.4. This version addressed a potentially seri- ous (although rare) server startup failure that was recently reported. This release is critical for users of PostgreSQL version 7.3.3, and highly recommended for all other PostgreSQL users. The latest version can be downloaded from the PostgreSQL FTP site . MySQL 4.0.14 MySQL.com announces the release of version 4.0.14. This release is a maintenance release for the current production version and includes functionality such as: a. Enabled `INSERT’ from `SELECT’ when the table into which the records are inserted is also a table listed in the `SELECT’. b. Changed optimiser slightly to prefer index lookups over full table scans. c. `FLUSH LOGS’ now rotates relay logs in addi- tion to the other types of logs it already rotated. For the full list of additions and bug fixes, or to down- load, visit MySQL.com . 8 August 2003 · PHP Architect · www.phparch.com php|a 10 August 2003 · PHP Architect · www.phparch.com Types of documents XML is commonly used to store several types of infor- mation. Not only do developers use it in their daily work to store configurations or define protocols, it is also a great way to structure your everyday documents, like letters, books, or articles. Even if they can be read with any text editor (XML is an ASCII format), XML doc- uments are not the first choice when it comes to docu- ments that you'd like to read in your free time. The mix- ture of tags, attributes and plain text may confuse you while you are trying to get to the actual information. XML was designed to be read by machines, not humans. XML does not contain any layout but only the structure of the raw data or content. An XML docu- ment consists of several tags (like HTML) which describe the information contained within the tags. Any program may use these tags to decide what to do with the text information between these tags. This could mean a program is able to prioritize parts of a document, if it had to create a search index or some- thing similar. Humans tend to decide what to do with the informa- tion they read according to how it has been laid out. If you are reading an article, you will surely recognize that the headline has some significance in the context of the rest of the article, as it is printed in bold and large let- ters. So if information has to be accessed by computers and humans, the best solution would be to present both species the same information in different formats. The first choice of delivering information to a machine is nowadays XML, while PDF can be read with almost every client and operating system, and can easily be printed, which enables you to take the information to wherever you'd like without the need for a computer. As we're living in the age of automation, you will not want to create both versions of the information on your own but use your friendly neighbourhood webserver and scripting language (PHP) for it. This article will explain one way to achieve this without a single drop of sweat Transforming documents To automate the generation of one version of the two required documents, you have to define which version should be created manually and which one should be generated by an application. This problem is solved in the blink of an eye, as the previous section explained Transforming XML to PDF with LaTeX By Stephan Schmidt PHP Version: 4.x and above O/S: Linux Additional Software: LaTex Code Directory: N/A REQUIREMENTS FF EE AA TT UU RR EE [...]... Once the client sent the customer's information to the server, the client would redirect the browser to the work-in-progress page This work-in-progress page required no interaction with the server and therefore wasn't impacted when the server restarted After the 30 seconds, the work-in-progress page would direct the browser back to the client script which could request the status of the account without... $s Then we use the setLine() method to set the line thickness (the first argument) and the colour (the last three arguments - red, green and blue) In this case, we specify a dark green The line $f=$s->addFill(0,255,0,255); adds a light green fill (the first three arguments) to the outline we are about to draw The last argument to addFill() is the "alpha" of the fill Alpha can be best explained as the. .. downward The other hot tip to know is that an object's depth in the movie corresponds to the order you added it to your movie Have a look at Figure 2 to see what I mean SWFMovie The first object we should look at in the Ming library is the SWFMovie object This is the object that handles the creation of our movie, setting the frame rate, the overall dimensions, the background colour, and also handles the. .. Directories" There August 2003 · PHP Architect · www.phparch.com 17 FEATURES Flash conventions Before we get into using Ming and draw up some movies, we should go over some conventions with Flash Flash movies have the origin of the movie at 0,0 This point is in the uppermost left corner From this point the x value increases from the left to the right, and the y increases as we go from top of the screen... separate PHP script from the player The script, called upload.php, uses a library developed by someone else (no sense re-inventing the wheel) that will read the MP3 header information and the ID3 tag The header information is needed to grab the length of the song It is absolutely imperative to retrieve this information because when we embed the MP3 into a SWF file we need to make sure the 21 FEATURES Ming... Listing 10 The script performs some basic validation of the uploaded file, strips out the ID3 tag and stores that as a new database record It then processes the MP3 by embedding it into an SWF file The Ming library is used for the last step, and the newly created SWF is saved to the local disk Make sure you have permissions set for the directory to be able to write files, or you could change the script... this whole movie going (see the bottom of Listing 13) The first thing we do is set the initial volume using the previously mentioned Vol Flash variable Then we load the SWF movie containing our MP3 using the loadMovie function into the empty movie clip called "mp3" Next, we create a new Sound object to handle the volume initially Lastly, we add the track information into the textfield That's it We are... you my findings Don't worry there won't be a three hour slideshow Let's take a little journey into the world of Ming with PHP The first stop is to investigate the website for the Ming library, and this site is located at http://ming.sourceforge.net Take the time to visit the site and scour through the function reference There is a nice list here, and using these classes and their methods we can do just... fill them with any content you can to find You may retrieve content from the user by supplying forms, get it from databases, or even XML files, which is the topic of the next section Transforming XML documents using patXMLRenderer As the title of this article is "Transforming XML to PDF with the help of LaTeX" we are now going back to where we came from and take a look at XML documents and how they... SWFTEXTFIELD_PASSWORD obscures the data entry SWFTEXTFIELD_DRAWBOX draws the outline of the text field SWFTEXTFIELD_MULTILINE allows multiple lines SWFTEXTFIELD_WORDWRAP allows text to wrap SWFTEXTFIELD_NOSELECT makes the field non-selectable You can also specify the height, width, type and size of the font using the methods of the SWFTextField object You can even specify the instance name of the text field so . have the origin of the movie at 0,0. This point is in the uppermost left corner. From this point the x value increases from the left to the right, and the. March 5 th 2004 See inside for details Get Ready For Maintenance Maintenance from the Outsetfrom the Outset Building a monitoring system Building a monitoring