Thông tin tài liệu
FEBRUARY 2004
VOLUME III - ISSUE 2
FEBRUARY 2004
VOLUME III - ISSUE 2
www.phparch.com
The Magazine For PHP Professionals
Plus:
Tips & Tricks, Security Corner, Product Reviews and much more
php|
Cruise
March 1
st
- March 5
th
2004
See inside for details
Get Ready For
Caching Techniques for the PHP Developer
Offline News Management with PHP-GTK
EXtending PHPEXtending PHP
Handling PHP Arrays from CHandling PHP Arrays from C
The Need for Speed
Writing More efficient PHP scripts
PROFILING PHPPROFILING PHP
Understand and optimize your code
Writing an riting an SMSSMS
Gateway ateway with ith
PHPPHP and and Gnokiinokii
]
]
Visit us at www
.php
arch.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!
In partnership with Zend
Technologies
Zend Studio 3.0 is the
official PHP IDE of
php|cruise
Features
php|
Crui se
Traditional PHP
Conference*
Conference Pass
$ 899.99
**
$ 1,150.00
Hotel
Included
($ 400.00)
Meals
Included***
($ 200.00)
Totals:
$ 899.99
$1,750.00
You Save $ 850
* Based on average of two major PHP conferences
** Based on interior stateroom, double occupancy
*** Alcohol and carbonated beverages not included
ENJOY LEARNING PHP IN A FUN AND EXCITING
ENVIRONMENT—AND SAVE A BUNDLE!
Signup deadline: Feb 15, 2004
5 Editorial
6 What’s New!
37 Product Review
SQLyog
58 Product Review
2003 Quebec PHP Conference DVD
by Marco Tabini
61 Security Corner
by Chris Shiflett
65 Tips & Tricks
By John W. Holmes
68 e x i t ( 0 ) ;
Why Can’t We All Just Get Along?
By Marco Tabini
9
Write SMS Applications With PHP and
Gnokii
by Eric Persson
16
Offline Content Management with
PHP-GTK
by Morgan Tocker
23
Writing PHP Extensions: Managing
Arrays
by Wez Furlong
28
The Need For Speed
Optimizing your PHP Applications
by Ilia Alshanetsky
41
Profiling PHP Applications
by George Schlossnagle
51
Caching Techniques for the PHP
Developer
by Bruno Pedro
3
February 2004
●
PHP Architect
●
www.phparch.com
TABLE OF CONTENTS
II NN DD EE XX
II NN DD EE XX
php|architect
Features
Departments
Existing
subscribers
can upgrade to
the Print edition
and save!
Login to your account
for more details.
NEW!
NEW!
*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.
**Offer available only in conjunction with the purchase of a print subscription.
Choose a Subscription type:
CCaannaaddaa//UUSSAA $$ 8833 9999 CCAADD (($$5599 9999 UUSS**))
IInntteerrnnaattiioonnaall SSuurrffaaccee $$111111 9999 CCAADD (($$7799 9999 UUSS**))
IInntteerrnnaattiioonnaall AAiirr $$112255 9999 CCAADD (($$8899 9999 UUSS**))
CCoommbboo eeddiittiioonn aadddd oonn $$ 1144 0000 CCAADD (($$1100 0000 UUSS))
((pprriinntt ++ PPDDFF eeddiittiioonn))
Your charge will appear under the name "Marco Tabini & Associates, Inc." Please
allow up to 4 to 6 weeks for your subscription to be established and your first issue
to be mailed to you.
*US Pricing is approximate and for illustration purposes only.
php|architect Subscription Dept.
P.O. Box 54526
1771 Avenue Road
Toronto, ON M5M 4N5
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: ____________________________________
Visit: http://www.phparch.com/print for
more information or to subscribe online.
Signature: Date:
To subscribe via snail mail - please detach/copy 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
YYoouu’’llll nneevveerr kknnooww wwhhaatt wwee’’llll ccoommee uupp wwiitthh nneexxtt
February 2004
●
PHP Architect
●
www.phparch.com
EE DD II TT OO RR II AA LL RR AA NN TT SS
php|architect
Volume III - Issue 2
February, 2004
Publisher
Marco Tabini
Editorial Team
Arbi Arzoumani
Peter MacIntyre
Eddie Peloke
Graphics & Layout
Arbi Arzoumani
Managing Editor
Emanuela Corso
Director of Marketing
J. Scott Johnson
scott@phparch.com
Account Executive
Shelley Johnston
shelley@phparch.com
Authors
Ilia Alshanetsky, Wez Furlong, John Holmes,
Bruno Pedro, Eric Persson, George Schlossnagle,
Chris Shiflett, Morgan Tocker
php|architect (ISSN 1709-7169) is published twelve times a year by Marco Tabini &
Associates, Inc., P.O. Box 54526, 1771 Avenue Road, Toronto, ON M5M 4N5, 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 asso-
ciated 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 © 2003-2004 Marco Tabini & Associates, Inc.
— All Rights Reserved
W
elcome to the February 2004 issue of
php|architect. As I write this, I'm sitting in my
office—about forty degrees Celsius warmer
than outside and, therefore, a much better place to
work in that that the local park—suffering from an
awful cold and sitting by a collection of (clean) tissues
discreetly stashed on my desk, ready for use. As you
can expect, I'm not particularly happy about either fact
(make that three facts—the cold outside, the cold in
my body, and the fact that I'm sitting in an office when
I could really be somewhere else far away from any-
thing that even remotely resembles a computer).
Incidentally, with php|cruise coming at the beginning
of March, I should hopefully be able to get rid of at
least two problems—and I'm still working on finding a
way to avoid computers during that trip.
But I ramble—a clear sign that the cold medicine is
wearing off. Let me instead tell you something about
this month's issue. With the popularity that PHP enjoys
nowadays comes the fact that it is used as the back-
bone of more and more high-traffic sites. A simple con-
sequence of this is that an increasing number of devel-
opers are "hitting the wall" and finally feeling the limits
of what the "let's just do it in PHP" approach can do.
Building a website is always a high-wire balance of
budgeting, respecting deadlines and writing the best
code possible, but there's nothing quite as bad as find-
ing out that the way you've done things is incapable of
meeting the demands of your website—and, by the
time you realize that you have a problem, it's usually
too late to think about a solution short of calling your
travel agent and inquiring about that non-extradition
country you heard of.
Therefore, this month we dedicate a fair amount of
room to the performance management of PHP applica-
tions. George Schlossnagle's article—based on an
excerpt from his latest book, published by SAMS—talks
about profiling, a concept that I have very rarely seen
associated with PHP applications. Profiling takes the
guesswork out of understanding where the bottlenecks
in your application are, allowing you to focus on find-
ing the best possible resolution.
The problem with profiling is that it only allows you
to identify the problems and not solve them. Luckily,
Ilia Alshanetsky and Bruno Pedro offer two other excel-
lent articles on improving the performance of PHP
without affecting the code itself (if you can, why not
avoid the risk of introducing even more bugs?). While
Ilia focuses on ways to make the PHP interpreter itself
run faster, Bruno examines the topic of caching—both
at the network and script level.
This month we also start a new column—Security
Corner—written by Chris Shiflett. The daily number of
security advisories, patches, break-ins and source-code
thefts that we see reported in the media every day has
EDITORIAL
Continued on page 8
February 2004
●
PHP Architect
●
www.phparch.com
6
NNEEWW SSTTUUFFFF
PHP 4.3.5 RC1
PHP.net has announced the
release of PHP 4.3.5 RC1
PHP 4.3.5RC1 has been released
for testing. This is the first release
candidate and should have a very low number of prob-
lems and/or bugs. Nevertheless, please download and
test it as much as possible on real-life applications to
uncover any remaining issues. List of changes can be
found in the NEWS file.
For more information visit:
http://qa.php.net/
PHP Community Logo Contest
Following Chris Shiflett’s recent announcement of the
PHP Community Site, he is holding a contest to
find a logo that embodies the spirit of the PHP
community. Everyone is welcome to participate,
and you can submit as Many entries as you like.
Please send all entries to logos@phpcommuni-
ty.org And include the name with which you want
to be credited.
The contest ends 29 Feb 2004, and php|architect is
offering a free PDF subscription to the winner. For
updated news about the contest, as well as a
chance to view the current entries, visit:
http://www.phpcommunity.org/logos/
Good luck to all who enter!
ZEND Studio 3.0.2
Zend has announced the release of Zend Studio 3.0.2
client. What’s new? Zend.com lists some of the bug
fixes as:
• ZDE didn’t load when using a new keymap
config from an older version.
• Save As Project didn’t always work.
• Server Center activator tried to open the
wrong URL.
• .js files were not opened with JavaScript
highlighting.
• Shift-Delete and Shift-Backspace didn’t work
properly.
• Find&Replace was very slow under Linux.
• Add Comment sometimes erroneously com-
mented out a line that wasn’t selected.
• Added configurable limit for the number of
displayed syntax errors
There have also been improvements to the debugger,
code completion, code analyzer, IE toolbar, and some
Mac OSX changes.
Get more information from
Zend.com.
What’s New!
NN EE WW SS TT UU FF FF
February 2004
●
PHP Architect
●
www.phparch.com
7
MySQL Administrator
MySQL.org announces: MySQL Administrator is a pow-
erful new visual administration console that makes it
significantly easier to administer your MySQL servers
and gives you better visibility into how your databases
are operating. MySQL Administrator integrates data-
base management and maintenance into a single,
seamless environment, with a clear and intuitive graph-
ical user interface. Now you can easily perform all the
command line operations visually, including configur-
ing servers, administering users, dynamically monitor-
ing database health, and more
Get more information from:
http://www.mysql.com/products/administrator/index.html
NNEEWW SSTTUUFFFF
Check out some of the hottest new releases
from PEAR.
DB 1.6.0 RC4
DB is a database abstraction layer providing:
• an OO-style query API
• a DSN (data source name) format for specifying
database servers
• prepare/execute (bind) emulation for databases
that don’t support it natively
• a result object for each query response
• Compatible with PHP4 and PHP 5
• much more….
DB layers itself on top of PHP’s existing database
extensions. The currently supported extensions
are: dbase, fbsql, interbase, informix, msql, mssql,
mysql, mysqli, oci8, odbc, pgsql, sqlite and sybase
(DB style interfaces to LDAP servers and MS ADO
(using COM) are also avaible from a separate pack-
age).
System_ProcWatch 0.4
With this package, you can monitor running
processes based upon an XML configuration file,
XML string, INI file or an array where you define
patterns, conditions and actions.
Net_IMAP 0.7
Provides an implementation of the IMAP4Rev1
protocol using PEAR’s Net_Socket and the option-
al Auth_SASL class.
XML_Beautifier 1.1
XML_Beautifier will add indentation and line
breaks to you XML files, replace all entities, format
your comments and makes your document easier
to read. You can influence the way your document
is beautified with several options.
Looking for a new PHP Extension? Check out
some of the latest offerings from PECL.
opendirectory 0.2.2
Open Directory is a directory service architecture
whose programming interface provides a central-
ized way for applications and services to retrieve
information stored in directories. The Open
Directory architecture consists of the
DirectoryServices daemon, which receives Open
Directory client API calls and sends them to the
appropriate Open Directory plug-in.
statgrab 0.1
libstatgrab is a library that provides a common
interface for retrieving a variety of system statistics
on a number of *NIX like systems.
This extension allows you to call the functions
made available by libstatgrab library.
Sasl 0.1.0
SASL is the Simple Authentication and Security
Layer (as defined by RFC 2222). It provides a sys-
tem for adding plugable authenticating support to
connection-based protocols. The SASL Extension
for PHP makes the Cyrus SASL library functions
available to PHP. It aims to provide a 1-to-1 wrap-
per around the SASL library to provide the greatest
amount of implementation flexibility. To that end,
it is possible to build both a client-side and server-
side SASL implementation entirely in PHP.
SQLLite 1.0.2
SQLite is a C library that implements an embedda-
ble SQL database engine. Programs that link with
the SQLite library can have SQL database access
without running a separate RDBMS process. This
extension allows you to access SQLite databases
from within PHP. Windows binary available from:
http://snaps.php.net/win32/PECL_STABLE/p
hp_sqlite.dll
PHPWeather 2.2.1
PHP Weather announces the release of version 2.2.1.
PHP Weather makes it easy to show the current weath-
er on your webpage. All you need is a local airport, that
makes some special weather reports called METARs.
The reports are updated once or twice an hour.
Get more information from :
http://sourceforge.net/projects/phpweather/
PHPEclipse Debugger
PHP Eclipse adds PHP support to the Eclipse IDE
Framework. This snapshot introduces the first version of
the PHPEclipse debugger plugin.
For more information visit:
http://www.phpeclipse.de
MySQL and Zend Working Together
From Zend and MySQL – These two have Joined Forces
to Strengthen Open Source Web Development
MySQL AB, developer of the world’s most popular open
source database, and Zend Technologies, designers of the
PHP Web scripting engine, today announced a partnership
to simplify and improve productivity in developing and
deploying Web applications with open source technolo-
gies. Through the alliance, the companies are improving
compatibility and integration between the MySQL data-
base and Zend’s PHP products to make it easier for busi-
nesses to use complete open source solutions, such as the
popular LAMP (Linux, Apache, MySQL and PHP) software
stack.
As part of the partnership, MySQL AB and Zend are
offering partner products to their respective customers,
enabling easier product procurement and deployment
for Web application infrastructures. The companies will
also commit development resources to design product
integration and compatibility modules for both ven-
dors’ platforms.
For more information visit:
www.zend.com
SAXY 0.3
SAXY is a Simple API for XML (SAX) XML parser for PHP
4. It is lightweight, fast, and modeled on the methods
of the Expat parser for compatibility. The primary goal
of SAXY is to provide PHP developers with an alterna-
tive to Expat that is written purely in PHP. Since SAXY is
not an extension, it should run on any Web hosting
platform with PHP 4 and above installed.
This release allows CDATASection tags to be pre-
served, rather than converted to Text Nodes.
For more information visit:
http://www.engageinteractive.com/saxy/
February 2004
●
PHP Architect
●
www.phparch.com
8
NNEEWW SSTTUUFFFF
php|a
convinced us that, at the very least, one should be able to protect his sites from malicious usage, in the hope
that all the other companies we rely on to maintain their software will do so in a serious way.
Finally, we bring you three more articles that, we hope, will tickle your fancy. The first one, written by Eric
Persson, shows you how you can build an SMS gateway using PHP and a few other inexpensive components.
SMS is not yet very popular here in North America, but, judging from the amount of people I see glued to
their cell phones whenever I visit my native Italy, it is very widely used in Europe.
In his article on offline news management, Morgan Tocker writes about how PHP-GTK, that most hidden of
PHP gems, can be used to improve content management by providing a proper GUI application that doesn't
require you to completely rewrite all your code.
Finally—last but not least-Wez Furlong picks up where his article from last month left off and delves into the
deep bowels of the Zend Engine to show you how a PHP extension written in C can manipulate PHP arrays—
it's not quite as easy as from a script but close enough once you know what you're doing.
Well, that's it for this month. By the time I will be writing my next editorial, I plan to be either boasting about
my suntan or complaining about sunburn. Either way, you can expect me to report on our adventure on the
high seas—until then, happy reading!
Editorial: Contiuned from page 5
D
espite the fact that it sounds like some mysteri-
ous Italian pasta, Gnokii is really just a project
aimed to develop tools and drivers for Nokia
mobile phones-that is, software that makes it possible
to control a Nokia phone physically connected to your
server via a serial port. Gnokii works like the Nokia Data
Suite, which is shipped with more advanced models
from Nokia: you can use it to send SMS messages, edit
contacts and so on—pretty much everything you nor-
mally do with your thumb on the phone's keypad.
Gnokii itself is composed of many tools, including a
set of GUI applications that facilitate the remote opera-
tion of the telephone; we are really only interested in a
small subset of these tools called
ssmmssdd
, or SMS daemon,
which provides an interface for rapid access to the
phone's SMS capabilities. With the SMS daemon up
and running, we can use PHP to interact with the
phone, send and receive SMS messages and, of course,
build whatever logic we need based on the content of
the messages that we receive and send. In short, my
goal with this article is to show you how to configure
software and hardware so that you can get the same
kind of service as you would normally obtain from a big
company selling mobile services like SMS gateways—
but at a fraction of the price.
Major Components of the Final
Application
The final application that we will create throughout this
article is a simple SMS server that awaits a message
from a user and acts on its contents. It is made up of
three major components:
• A Nokia cell phone, which must be
connected properly to the server.
• The
ssmmssdd
application from the Gnokii
package, which must, of course, be
compiled and configured correctly.
• The PHP scripts that provide the actual
server functionality.
The flow of the application will be as follows:
• The user send an SMS message to the
server.
• The
ssmmssdd
daemon picks it up and auto-
matically puts it into its database.
• Our server scans
ssmmssdd
's database peri-
odically for new messages.
• When a new message arrives, its con-
tents are examined and the server acts
on them, for example by replying to
the user with another message.
February 2004
●
PHP Architect
●
www.phparch.com
9
FF EE AA TT UU RR EE
Write SMS Applications With PHP and Gnokii
by Eric Persson
PHP: 4.1 or higher
OS: Unix/Linux
Applications: Gnokii (http://www.Gnokii.org)
Code: http://code.phparch.com/20/3
Code Directory: sms-gnokii
REQUIREMENTS
SMS-shorthand for Short Message Service-is the standard
used by cellular phone networks worldwide to allow their
customers to exchange small text messages using their
handsets. Despite its limitations, SMS is very popular
with cell phone users-and it has rapidly become a wide-
ly-used bridge between the Internet and mobile users.
[...]... web-based and a GTK version of the same application if they both use OOP techniques Finally, try to separate your code from your desired output, so that you can create a file like data .php and share it between the two without the need to branch your code February 2004 ● PHP Architect ● www.phparch.com 21 Can’t stop thinking about PHP? Write for us! Visit us at http://www.phparch.com/writeforus .php Writing PHP. .. counter For REQUIREMENTS PHP: 4.3+ OS: N/A Other Software: Working PHP source and compiler environment Code: http:/ /code. phparch.com/20/2 Code Directory: extensions 23 FEATURE Writing PHP Extensions: Managing Arrays each person, we allocate a PHP variable using the MAKE_STD_ZVAL() macro, we set it up as an array (lines 17 and 18), and then we step through each of their names and add them as string elements... breaking working code Whenever possible, it is always better to optimize things outside of your code that will have a positive impact on the performance of your applications As you can probably guess, the focus of this article will be optimizations that do not actually require code modification and still make your PHP applications run much faster February 2004 ● PHP Architect ● www.phparch.com Getting... array/object/integer (or whatever it was supposed to be) and that it is not empty/null Personally, I look forward to the release of PHP 5 and exception handling, when GTK & PHP can be taken to the next level and it will become easier to tackle these issues Portability, Recycling, and Reusing Another good idea is to try and store the important parts of your code nested in function calls, as opposed to using... \_supervise smsparse 0:00 \_/usr/local/bin /php -q /smsparse/smsparse .php php: /usr/local/bin /php /usr/local/lib /php /usr/local/lib /php. ini This means that I have the PHP interpreter's binary installed in /usr/local/bin /php It's now time to create a service directory for our service We'll start by creating a "service" directory for February 2004 ● PHP Architect ● www.phparch.com Keeping Tabs on the Situation... S S S S S ● PHP Architect 0:00 /bin/sh /command/svscanboot 0:01 \_ svscan /service 0:00 \_ supervise smsd 0:00 | \_ /usr/local/gnokii/bin/smsd -u xxx -p xxx -d xxx -m mysql 6:26 \_ supervise smsparse 0:00 | \_ /usr/local/bin /php -q /opt/www/smsparse/smsparse .php 0:00 \_ supervise log 0:01 \_ multilog t /main ● www.phparch.com 13 FEATURE Write SMS Applications With PHP and Gnokii Your Own PHP Daemon:... applications and systems Wez is a Core Developer of PHP, having contributed SQLite, COM/.Net, ActivePHP, mailparse and the Streams API (and more) and is the "King" of PECL -PHP' s Extension Community Library His consulting firm can be reached at http://www.thebrainroom.net To Discuss this article: http://forums.phparch.com/124 27 The Need For Speed Optimizing your PHP Applications F E A T U R E by Ilia Alshanetsky... http://forums.phparch.com/127 Tips for Writing Applications with PHP- GTK Error Checking The lifespan of your typical PHP- GTK application is usually longer than that of its web-based counterparts It will have to keep running for several hours, with functions being called over and over again For a GTK application, you may find that you will want to manage your error handling, and check the integrity of your variables... improving performance Most opcode cache implementations and there are several of them on the market nowadays-go even further and actually optimize the opcodes before storing them During the traditional compilation process, the PHP parser tries to speed up the opcode generation process and does not always generate the most optimal instructions for the Zend Engine to execute With an opcode cache, since the... compiler to optimize the generated code to the fullest The end result is that the compiled PHP executable is anywhere between 10% and 25% slower than it would be had it been compiled statically into Apache # PHP configure line /configure with-apache=/path/to/apache_source # Apache configure line /configure activatemodule=src/modules /php4 /libphp4.a The configuration procedure above will compile PHP directly . efficient PHP scripts
PROFILING PHPPROFILING PHP
Understand and optimize your code
Writing an riting an SMSSMS
Gateway ateway with ith
PHPPHP and and Gnokiinokii
]
]
Visit. Techniques for the PHP Developer
Offline News Management with PHP- GTK
EXtending PHPEXtending PHP
Handling PHP Arrays from CHandling PHP Arrays from C
The
Ngày đăng: 24/01/2014, 14:20
Xem thêm: Tài liệu PROFILING PHP Understand and optimize your code docx, Tài liệu PROFILING PHP Understand and optimize your code docx