Escolar Documentos
Profissional Documentos
Cultura Documentos
07
Cutting-Edge Technologies for Web Professionals
The Oracle PHP Connection
How to Get Well Connected and
What the Future Holds Once You Are
PHP Databases Special
MaxDB on the Web with PHP
An Introduction to the MaxDB PHP Interface
Slony Replication by Example
Building the Slony Cluster
Ruling the Turf with PHP and IBM Databases
Capitalize on the Best of Both Worlds
2
I n t e r n a t i o n a l P H P M a g a z i n e 0 4 . 2 0 0 7
Table of Contents
www.php-mag.net
06 Whats New in the PHP Community
23 Slony Replication by Example
Building the Slony Cluster
The ability of providing copies among instances of the
database engine is known as replication. This article talks
about Slony, which is the most popular form of master-
slave replication used on PostgreSQL today.
by Robert Bernier
05 The Oracle PHP Connection
How to Get Well Connected and What
the Future Holds Once You Are
In this article we take a look the connection methods
used for PHP and Oracle database using the PHP OCI8
extension. Specifcally we cover non-persistent and
persistent connections while offering some suggestions
for choosing the right approach. In addition we will cover
some upcoming features in the next major release of the
Oracle database to signifcantly improve scalability of
PHP applications.
by Richard Rendell
PHP Databases Special
3
I n t e r n a t i o n a l P H P M a g a z i n e 0 4 . 2 0 0 7
April 2007 Issue
16 MaxDB on the Web with PHP
An Introduction to the MaxDB
PHP Interface
The article presents an introduction to working with
the PHP interface from MaxDB. It is intended for PHP
users and developers already familiar with the use of PHP
extensions and, perhaps, with MaxDB itself. This article
tells you what you need to install MaxDB PHP, how
you can use its features and how you can convert your
MySQL applications to MaxDB PHP.
by Thomas Simenec
37 Ruling the Turf with PHP
and IBM Databases
Capitalize on the Best of Both Worlds
With the release of ibm_db2, PDO_IBM, and PDO_
INFORMIX extensions, IBM has provided a simple
to use, high performing, and very stable database
connectivity layer to the PHP community. The article
attempts to highlight the IBM value proposition and
provides a perspective straight from the gatekeepers
of these offerings to enable development of robust,
enterprise class web applications using PHP and IBM
databases.
by Srini Bhagavan, Kellen Bombardier
Want to Sponsor/Exhibit?
Email: info@jaxindia.com
Phone: +91 80 411 24 392/3
R
THIS YEARS MUST ATTEND FOR IT PROFESSIONALS
Three Conferences In One Package. Cutting-edge Sessions Delivered by
Community and Industry Luminaries.
Venue :
Date :
National Science Symposium Centre, IISc, Bangalore, India
28-31 May 2007
O7
OlSCOVEH TME POWEH OF TMHEE-lM-OME
www.jexindie.ccm
Presents
Media Sponsors
YOUR RIGHT TO INFORMATION TECHNOLOGY
Platinum Sponsor Gold Sponsor
The Oracle PHP Connection PHP Databases Special
I n t e r n a t i o n a l P H P M a g a z i n e 0 4 . 2 0 0 7
5
P
HP applications of all types and sizes are being built
using the Oracle database. Using the free Oracle Express
Edition (XE) and the equally free SQL Developer or
JDeveloper, getting up and going with Oracle has never been
more accessible--or cheaper! Whether you are building a
prototype, or a business critical PHP application the initial
step to using all that database technology is to connect to
it. The choice of connection method and how you manage
database connections in the PHP application can have a
dramatic effect on performance. So here we will explore
the ways in which you can connect to an Oracle database
from your PHP application, including the types of Oracle
connections, environment variables and semantics of each
connection method. Finally we will take a look at scalability
of PHP applications and the Oracle connection pooling
approach specifcally developed to increase performance of
multi-process clients such as PHP.
Overview
When I initially got involved in our PHP efforts one of the
most interesting aspects was discovering what customers
were actually doing with PHP and Oracle. Customers were
showing us their wow factor with Oracle and PHP long
before well, those other wow guys. Heres just some of
The Oracle PHP Connection
By Richard Rendell
In this article we take a look the connection methods
used for PHP and Oracle database using the PHP OCI8
extension. Specifcally we cover non-persistent and
persistent connections while offering some suggestions
for choosing the right approach. In addition we will cover
some upcoming features in the next major release of the
Oracle database to signifcantly improve scalability of PHP
applications.
How to Get Well Connected and What
the Future Holds Once You Are
the categories and types of PHP applications our customers
are building using the Oracle database:
Enterprise portals
Content and Records Management
Trading and web commerce
Multimedia
Spatial
OLAP and Business Intelligence
Life Sciences
Pharmaceuticals
Education
Data warehousing and mining
Some of these applications contain over a million lines of
PHP code and at least as many users. Also, several open source
projects have chosen to add Oracle as a supported database. Most
recently the folks at Drupal were kind enough to write about
their experiences doing exactly that in the Oradrup project [1].
#!/bin/sh
TNS_ADMIN=/usr/local/apache/conf
export TNS_ADMIN
echo Starting Apache
#export > /tmp/envvars
/usr/local/apache/bin/apachectl start
Listing 3: start_apache.sh
The Oracle PHP Connection PHP Databases Special
I n t e r n a t i o n a l P H P M a g a z i n e 0 4 . 2 0 0 7
9
Connections opened with oci_pconnect() will not be closed by
oci_close(). This is similar to the way persistent resources work in
other PHP extensions. Idle persistent connections can be set to
expire.
The oci_close() function was a no-op prior to the re-
factoring of OCI8. That is, it had no functional code, and did
not actually close a connection. You could not explicitly close
connections even if you wanted to! This has now changed, but
you can revert to the old behavior if necessary with this php.
ini setting:
oci8.old_oci_close_semantics = 1
Semantically, oci_close() works by reference counting.
Only when all references to the PHP connection are
finished will the database connection actually be closed. In
this example $c1 and $c2 are the one database connection
(because oci_connect returns the same connection resource
when called more than once in a script), but only at the
end of script is the database connection really closed. See
Listing 4.
In Listing 4, the second query fails, but the third succeeds.
Although the reference counting algorithm keeps the database
connection physically open, the connection resource in $c1 is
not usable after oci_close ($c1) is executed.
Connection Management in
Scalable Systems
Oracle achieves its well-known scalability in part through a
multi-threaded architecture. PHP instead has a multi-process
architecture. This difference means care is required when
designing scalable applications.
Using persistent connections is common for web sites that
have high numbers of connections being established. Reusing
a previously opened connection is signifcantly faster than
opening a fresh one. Large sites should benchmark persistent
PHP connections and Oracle Shared Servers also known as
Multi Threaded Servers (MTS). Shared Servers reduce the
numbers of processes needed to handle database requests.
Make sure that you understand the lifetime of your
applications connections. Reuse connections where possible,
but dont be afraid to create new connections and close them
as needed. Each connection will take some Oracle memory, so
overall load can be reduced if idle connections are closed with
Apache process timeouts or with the php.ini parameters to
expire persistent connections.
For sites with hundreds of connections a second, tune the
cache size of an internal sequence generator, sys.audses$. A
starting point is to change it to perhaps 10000:
SQL> alter sequence sys.audses$ cache 10000;
This is also recommended if you are using Oracle RAC
(Real Application Clusters).
With Oracle RAC you can adjust the algorithm that decides
which Oracle node handles each new connection. Set the listener.
ora parameter
PREFER_LEAST_LOADED_NODE_<listener_name> to OFF to use
session based load balancing.
This is documented in Note 220970.1 on Oracles Metalink
support site.
Session-based load balancing takes into account the number
of sessions connected to each node and then distributes new
connections to balance the number of sessions across the
different nodes. This can help when there is a connection storm
<?php
function do_query($c, $query)
{
$s = oci_parse($c, $query);
oci_execute($s);
oci_fetch_all($s, $res);
echo <pre>;
var_dump($res);
echo </pre>;
}
$c1 = oci_connect(hr, hr, //localhost/XE);
$c2 = oci_connect(hr, hr, //localhost/XE);
do_query($c1, select user from dual);
oci_close($c1);
do_query($c1, select user from dual); // fails
do_query($c2, select user from dual); // succeeds
oci_close($c2);
?>
Listing 4: close.php
PHP Databases Special The Oracle PHP Connection
10
I n t e r n a t i o n a l P H P M a g a z i n e 0 4 . 2 0 0 7
and the normal allocation metrics do not get a chance to get
updated fast enough. For both RAC and non-RAC database,
the DBMS_SERVICE package lets you specify workload
management goals. This is a detailed topic; refer to Oracles
manuals for more information. Finally, make sure that your
applications are as effcient as possible, which should minimize
the length of time connections are held.
Now that pretty much covers the best practices with
current technology, but to scale performance beyond what we
have today for multi-process clients like PHP, Oracle is adding
a server side connection pool, which will manage a pool of
active connections ready to go.
Pooling Software Objects
In general pooling objects is an optimization that is widely
adopted in many scenarios. Pooling an object makes sense if
the object is:
Required for a relatively short duration
Expensive to create every time it is required
Expensive to tear down when not required
Expensive to maintain all the time (even when not required)
because it consumes resources
Pooling such objects enables the user that needs the object
to quickly access it from the pool and release it back when the
object is not required, thereby enabling other users to reuse
the pooled object. This typically improves system performance
dramatically.
Pooling Database Connections
Database connections generally satisfy all of the earlier
mentioned criteria. Database connection establishment
involves creation of the network connection, spawning an
associated operating system process/thread, performing the
requisite authentication, creation of the session involving
session private contexts for SQL statement, and so on. Tearing
down database connections is also expensive. And needless to
state that unnecessarily maintaining them when not required
just eats up precious resources on the database server. That
explains why database connection pooling greatly helps high
traffc web applications where connections are needed for
short durations. Most multithreaded systems that talk to a
database offer some form of database connection pooling.
Developers
Designers
Project Managers
Online Marketing Strategists
webinale 07 is positioned as a platform that will enable
the Next Generation Web for you. Top-notch speakers
who will not only demonstrate the best Practices, but
also guide you along the way will deliver cutting-edge
sessions. Information that you gather at webinale 07
will be most relevant for your day-to-day projects.
Interested in Advertising, Exhibiting or Sponsoring?
Please visit
webinale-asia.com
Singapore,
webinale-asia.com
23-24 April 2007
FOUR SERVICES.ONE SOURCE.
'OLD3PONSOR
ou can also visit http://www.impigertech.com/
wizard/.
WHERE DO YOU WANT TO
MEET YOUR CUSTOMER?
S&S Media
CHAMPIONING CROSS MEDIA COMMUNICATIONS
S&S MEDIA PTE LTD
l33 NLw 8P|DGL POAD #08-l0 CH|NATOwN PO|NT
S|NGAPOPL 0594l3
TEL: +65 6435 0260 (MA|N L|NL) FAX: +65 6887 3842
E-MAIL: advertisesda-asia.com
WebSite:www.softwaresupportmedia.sg
Software & Support Verlag GmbH
Geleitsstrae l4
60599 Prankfurt am Main, Germany
Phone: +49 (0) 69 63 00 89 0 Fax: +49 (0) 69 63 00 89 89
E-mail: sda-asiasoftware-support.biz
Website:www.software-support.biz
S&S Media
MLNAPA KAD|N |NDONLS|A,
1AKAPTA l2950, |NDONLS|A
Phone: +62 2l 5263083 Fax: +62 2l 5299 4599
E-mail: contactusmedia-ti.co.id
WebSite:www.media-ti.co.id
S&S Media
#l5/6, | PLOOP, PP|MPOSL POAD,
8ANGALOPL - 560 025
Off: +9l 80 4ll24392/3 Pax: +9l 80 4ll2439l
E-mail: editorssda-india.com
WebSite:www.softwaresupportmedia.in
FOUR SERVICES. ONE SOURCE.
S&S
Media
Print
(Magazine)
Custom
Events
Branded
Conference
Online