SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2002
    Ottawa, Ontario, Canada
    0 Post(s)
    0 Thread(s)

    Connection pooling for PHP!

    Hi all,

    I just wanted to pass along an interesting SourceForge project I learned about this morning. The project is called SQL Relay.

    Here are a couple quotes from the SQL Relay FAQ page.

    What is SQL Relay?

    SQL Relay is a persistent database connection pooling, proxying and load balancing system for Unix and Linux supporting ODBC, Oracle, MySQL, mSQL, PostgreSQL, Sybase, MS SQL Server, IBM DB2, Interbase, Lago and SQLite with APIs for C, C++, Perl, Perl-DBD, Python, Python-DB, Zope, PHP*, Ruby, Ruby-DBD and Java, command line clients, a GUI configuration tool and extensive documentation. The APIs support advanced database operations such as bind variables, multi-row fetches, client side result set caching and suspended transactions. It is ideal for speeding up database-driven web-based applications, accessing databases from unsupported platforms, migrating between databases, distributing access to replicated databases and throttling database access.
    *bold/italic PHP is my formatting.

    This is more to anyone else that uses Oracle like myself:
    Let's say you're using Apache, PHP and Oracle and you determine by doing all sorts of analysis that you need to keep 30 Apache processes running to provide adequate response. Since most of your site isn't database-driven, on average, no more than 5 PHP's actually access the database simultaneously. Currently, you're using persistent connections to defeat the time-cost of logging into Oracle, but you have to maintain 30 connections (1 per web server process) which takes up a lot of memory on both the web server and database server and you really only need 5 connections. By using SQL Relay you can reduce the number of Oracle connections to the 5 that you need, continue to run 30 Apache processes and reclaim the wasted memory on both machines.
    It looks interesting so far. I am going to read up on it hopefully by early next week

    Has anyone here had an experience with this project?


  2. #2
    SitePoint Addict
    Join Date
    Apr 2002
    0 Post(s)
    0 Thread(s)
    SQL relay solution exists for PHP for a long while but connection pooling in general will tend to slow down your site a bit as it will often make it wait for the database connections to reopen during a surge. If you need database access in most of your site scripts, the slow down may be significant.

    BTW, it seems that for instance Oracle OCI API comes with built-in support for connection pooling but PHP OCI API is not making use of that.

    Anyway, one important point that most people is not aware is that the setup of Apache 1.x + PHP with persistent database connections tends to open much more database connections than it would really need because usually you server dynamic and static content with the same Web server.

    A better solution is to move all static content (like graphic images) to be served by a separate HTTP server, probably running in the same IP but on a different port. The consequence of this is that Apache will pre-fork much less processes (especially on sites that abuse of graphics) and so PHP would open much less persistent connections as it would run on much less Apache processes.

    A good candidate for serving static content is thttpd. It uses only one process serving many files with non-blocking I/O. It serves static content much faster than Apache 1.x . There is a Windows port for those stuck with Windows.

    If you run Linux, Tux HTTP kernel module is even much faster, although it seems nobody is using it precisely because it is a kernel module.

    There are many other solutions for serving static content efficiently including Apache 2 but I have not experienced them to comment.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    0 Post(s)
    0 Thread(s)
    When I experimented with it, it was rubbish.

    I tried persistant connections + SQL relay and it was slower than non-persistant connections!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts