Webserver hangs connecting to SQL2005.

Posted on 2009-02-19
Last Modified: 2013-12-12
Occasionally our website seems to 'hang'. No pages get returned to the browser.
webserver: Win2k3 IIS6 Zend 2.5.2
Db server: MS MSQL 2k5 on another box
When this happens the Application Log in event viewer on the webserver has a whole series of errors like this:
"Can not connect() to C:\Program Files\Zend\Core\bin\php-cgi.exe - [10060]"

Sometimes the error number is 1460:

"Can not read response from C:\Program Files\Zend\Core\bin\php-cgi.exe - [1460]"

These messages appear several times a second in the log.

Restarting the Web Service fixes the problem for several hours. Then it occurs again.

Any ideas where my problem lies?

Many thanks for any help....
Question by:hc11
    LVL 9

    Expert Comment

    by:Sander Stad
    Did you place a firewall on the machine after the installation on the webserver.

    You could try the to delete the entry from the following registrykey :

    LVL 22

    Expert Comment

    This sounds like it might be a memory issue that is causing PHP to hang and not respond.
    When this happens see what is running on the server.  If there are PHP processes running try aborting them and then see if the problem clears up.

    If this works then it could be that PHP needs to be patched or there is a problem with the code that is running and something is hanging and possibly chewing up memory which eventually hangs the system.

    Author Comment

    Thanks for your suggestions so far.

    I don't believe there has been a firewall added to the machine. But if so surely this wouldn't cause the intermittent connection problem I described?

    I just checked the machine while it was is this 'stuck' state. It had exactly the same number of php-cgi.exe threads running as when all is well (16 as set in Zend). They are all using the same amount of memory as they do when successfully serving pages (around 13MB). The processor utilisation of these threads was always at zero though, whereas when serving pages the threads that do the serving will jump from zero up to a few percent each briefly as they do their job.

    The uncanny thing about this problem seems to be that while the machine is stuck and not serving pages the CPU load is much lower than when it is.
    The only thing going on seems to be the errors adding to the App log.

    Both the system and the data partitions have loads of free space.

    Can anyone suggest anything else?

    many thanks


    Author Comment

    Perhaps I should clarify. When I said:

    "I don't believe there has been a firewall added to the machine. But if so surely this wouldn't cause the intermittent connection problem I described?"

    I meant: If the firewall was a problem for the connection between the webserver and the db server then surely it would stop ALL connections rather than just some as I am seeing??

    Sorry about the confusing double negative in the quoted comment.

    Author Comment

    Well. I have submitted a Zend support ticket since investigation on this forum was fruitless.

    LVL 22

    Expert Comment

    My take, this is a code issue.
    it may not be a memory leak as opposed to a pice of code that is trying to use more memory than the process can handle.  If this happens then you get a small app that uses all of its memory but needs more so it is constantly doing memory checking to free up anything not in use and slowly (if at all) working on the request.  Now, if the request happens to center around file IO then this could hang the entire environment.  A lot of applications are single threaded when it comes to IO and disk access so if one of the 16 processes hangs while reading a file then as the other processes all get to the point of needing access to a file they will go into a wait state while the pending file access is to be completed ... which it probably never will.  Eventually all the processes will hang.

    This can also be intermittent if the memory required by the "hung or slow" process is actually able to complete and then all the rest of the processes will catch up in their requests and everything goes back to normal.

    Author Comment

    Hmmm very interesting comment! Thank very much.
    But the question is how to test this?? Increase the memory allocation to my php threads and see if it goes away?
    Some code analysis tool?

    thanks again

    LVL 22

    Accepted Solution

    If you want to test this try a test server and configure it for 1 instance ... run a load test against it with a number of different requests for information and see if you can get 1 instance to hang or produce the errors.  If you can then you know it is something code specific within a single instance.  
    If this does not work then increase the number of threads/processes to 2.  Repeat the tests from above.  This might  be able to generate the errors messages you are seeing since you now have a multi-process environment.  It is possible that you might need to increase the threads/processes more in order to generate enough over-head and disk accesses so that you can generate the delays and create the same conditions.  

    This method should get you to the point of determining the contention level of the processes.

    If you can get up to 10 (or what ever the magic number is) before you start to see contention and the hanging of the processes then you can mitigate this by setting up multiple back-end processes and load balancing between them ... they will have to be unique instances, not sharing the same files or code if this is the case.

    Or you can contact the developers and see if they can come up with a fix  :)

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now