PHP ODBC AS400 - When running query new connections to site cant be opened.

Posted on 2009-04-27
Last Modified: 2013-11-19
Runing Zend/IIS/PHP I have a program that will connect out to our AS/4000 to do some budget cals, however when this is running on the as/400 it prevents any one from accessing the website until the query is done on the as/400 which can be upto 15min.

User 1 goes to website and starts the budget calc process,  User 2 tries to load up the website but cant, basically will sit there waiting for the connection until it times out or User 1's calc finishes and then User 2 can get to the website.

I have mysql queries that take 20min to run and people are able to access the site just fine, only happening when I connect out to the as/400.
Question by:bakes82
    LVL 22

    Expert Comment

    it would seem like you have a single PHP process running in the backend to process requests and that when the SQL call to the AS400 is made it is not spinning it off into a thread so that it locks up PHP and all requests until it has completed executing.

    Check you connection code for the PHP database connection and make sure you are in fact using ODBC.  If you are, see if there is a different ODBC client that will work.  This would appear to be an issue with how PHP is interacting with the AS400 database connection ... which means it is either in the code for the connection or with the ODBC drivers.

    Author Comment

    Below is my connection code and one of the files.
    The ODBC driver is the official Drive that IBM released from there iSeries client access.  (Guess Ill look and see if I try a diffrent one)
    $hostname_as400 = "as400";
    $username_as400 = "username";
    $password_as400 = "password";
    $as400 = odbc_connect($hostname_as400, $username_as400, $password_as400); 
    if ($as400 == false) {
    echo "Not able to connect to database...<br>";

    Open in new window

    LVL 22

    Accepted Solution

    As I guessed, PHP is not multi-threaded which means when this executes it is just hanging the entire PHP engine until this completes, keeping it from servicing any other requests.

    I found this page ( that has some ideas on how to handle this but none of them looked all that great to me.  I will see what else I can find.  A forking process would be fine if you can pass or access the data from the child process.  Or change your app so that every request that comes into the server is a forked process and then monitor the number of forked processes within the main/parent app.

    Author Comment

    That doesnt seem right, as I run MYSQL queries on the same system for 30-1hr just fine and people are able to still access the site.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Lync server 2013 Backup Service Error ID 4049 – After File Share Migration
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now