# Apache/PHP hangs on POST/submit form

## selig

I have been having this problem for months. I have a webhosting server and from time to time, every submit of any PHP form hangs. There are no errors in the log and I have updated all packages over the previous months. I even created a brand new chroot with all packages compiled from scratch and installed a new kernel but nothing helps. It seems random, sometimes the server can last for a couple of weeks without any problem but then there are days when it happens several times. It used to be worse when I had the worker MPM, I have switched to prefork in the meantime. That helped a bit but did not solve the problem. I have also tried decreasing the max requests per child directive, in hopes that if PHP leaks or hangs, the process will get restarted more frequently, solving the problem. But it did not really help either.

Now I do not know what else to try or where to look. Any ideas would be appreciated.

----------

## audiodef

What kind of webhosting server? Shared, virtual private or rented hardware? I assume the server OS is Gentoo, since you're posting here.

----------

## selig

It is my own hardware, nothing virtual.

----------

## audiodef

Can you post:

emerge --info

emerge -pv apache

emerge -pv php

?

----------

## selig

emerge --info:

```

Portage 2.1.10.65 (unavailable, gcc-4.5.3, glibc-2.14.1-r3, 3.0.4-hr5 x86_64)                                                                                                       

=================================================================                                                                                                                   

System uname: Linux-3.0.4-hr5-x86_64-Intel-R-_Xeon-R-_CPU_E5520_@_2.27GHz-with-gentoo-2.0.3                                                                                         

Timestamp of tree: Unknown                                                                                                                                                          

dev-lang/python:          2.7.2-r3::gentoo, 3.2.2::gentoo                                                                                                                           

sys-devel/autoconf:       2.68::gentoo                                                                                                                                              

sys-devel/automake:       1.11.1::gentoo                                                                                                                                            

sys-devel/binutils:       2.21.1-r1::gentoo                                                                                                                                         

sys-devel/libtool:        2.4-r1::gentoo                                                                                                                                            

sys-kernel/linux-headers: 3.1::gentoo (virtual/os-headers)                                                                                                                          

Repositories: x-portage                                                                                                                                                             

ACCEPT_LICENSE="* -@EULA"                                                                                                                                                           

CFLAGS="-O2 -mtune=core2 -march=core2 -pipe -fforce-addr"                                                                                                                           

CHOST="x86_64-pc-linux-gnu"                                                                                                                                                         

CONFIG_PROTECT="/etc /var/qmail/alias /var/qmail/control /var/vpopmail/domains /var/vpopmail/etc"                                                                                   

CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gentoo-release /etc/php/apache2-php5.3/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/cli-php5.3/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"                                                                                                               

CXXFLAGS="-O2 -mtune=core2 -march=core2 -pipe -fforce-addr"                                                                                                                         

DISTDIR="/usr/portage/distfiles"                                                                                                                                                    

FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles news parallel-fetch parse-eapi-ebuild-head protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"                                                                                                                         

GENTOO_MIRRORS="ftp://ftp.fi.muni.cz/pub/linux/gentoo/"                                                                                                                             

PKGDIR="/usr/portage/packages"                                                                                                                                                      

PORTAGE_TMPDIR="/var/tmp"                                                                                                                                                           

PORTDIR="/usr/portage"                                                                                                                                                              

PORTDIR_OVERLAY=""                                                                                                                                                                  

SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"                                                                                                                               

USE="apache2 berkdb bzip2 caps clamav curl expat fam fontconfig ftp gd gdbm geoip gs iconv imap ithreads jpeg jpeg2k lm_sensors logrotate memlimit mmx mysql mysqli ncurses perl perlsuid php pic png python slang spell sse sse2 threads tiff truetype xml"

Unset:  ACCEPT_KEYWORDS, EMERGE_DEFAULT_OPTS, PORTAGE_BUNZIP2_COMMAND

```

emerge -pv apache:

```

[ebuild     U  ] app-admin/apache-tools-2.2.23 [2.2.22] USE="ssl" 5,357 kB

[ebuild     U  ] www-servers/apache-2.2.23 [2.2.22-r1] USE="ssl suexec -debug -doc -ldap (-selinux) -static -threads" APACHE2_MODULES="actions alias auth_basic auth_digest authn_alias authn_dbd authn_default authn_file authz_default authz_groupfile authz_host authz_owner authz_user cgid dbd deflate dir env expires ext_filter filter headers ident imagemap include log_config mime mime_magic negotiation rewrite setenvif status vhost_alias -asis -authn_anon -authn_dbm -authz_dbm -autoindex -cache -cern_meta -cgi -charset_lite -dav -dav_fs -dav_lock -disk_cache -dumpio -file_cache -info -log_forensic -logio -mem_cache -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -proxy_scgi -reqtimeout -speling -substitute -unique_id -userdir -usertrack -version" APACHE2_MPMS="prefork -event -itk -peruser -worker" 63 kB

```

emerge -pv php:

```

[ebuild  NS    ] dev-lang/php-5.4.6 [5.3.11] USE="apache2 berkdb bzip2 calendar cjk cli crypt ctype curl fileinfo filter ftp gd gdbm hash iconv imap ipv6 json mhash mysql mysqli nls pdo phar pic posix readline session simplexml soap spell ssl tokenizer truetype unicode xml xmlreader xmlrpc xmlwriter xsl zip zlib -bcmath -cdb -cgi -curlwrappers -debug -doc -embed -enchant -exif -firebird -flatfile -fpm (-frontbase) -gmp -inifile -intl -iodbc -kerberos (-kolab) -ldap -ldap-sasl -libedit -mssql -mysqlnd -oci8-instant-client -odbc -pcntl -postgres -qdbm -recode -sharedmem -snmp -sockets -sqlite3 (-sybase-ct) -sysvipc -threads -tidy -wddx -xpm" 10,774 kB

```

Also I found out that very simple PHP scripts do not hang on POST - but when it comes to opening wordpress sites or sending some support tickets, etc., it becomes very slow - top shows nothing, Apache seems to be sleeping and not using CPU at all.

When I check the log while it is stalling, it shows nothing. The corresponding line in the log appears only after the page has been successfully downloaded but it shows the correct time (when I sent the request).

----------

## lxg

Is it possible that the bottleneck is your MySQL server? For example it might be that slow queries on a large data basis cause MySQL to have too many open connections, and (depending on its configuration) it waits until a new slot is available.

What types of PHP applications do you have installed? In your WordPress installation(s), what plugins do you use? Did you try deactivating them? Sometimes they are horribly coded and cause the weirdest problems.

----------

## selig

MySQL is not the bottleneck, it is not doing anything when this problem occurs. Also, there are not many open connections to the database.

The biggest problem is that it is a webhosting server and I have no control over what my customers are using. I cannot just go and disable some wordpress plugins in their installation. Unfortunately, this makes it really difficult to trace the root of the problem. I am quite sure that something must trigger it, some weird PHP script one of my customers is using, a wordpress plugin, something like that. On the other hand, since I am using apache/prefork, the processes should be isolated and even if one of them slows down, the rest should work normally.

----------

## lxg

 *selig wrote:*   

> The biggest problem is that it is a webhosting server and I have no control over what my customers are using.

 

Yup, what you're experiencing are the common problems of a virtual hosting provider. Unless you're offering real virtualization and resource provisioning, one customer can drag the entire server down.

Are you using Munin? If not, you should really consider installing it. If you already have it, I would recommend to assign virtual identifiers to your customers and monitor their ressource usage. For example, as for Apache, you could set up virtual, internal IP addresses (one for each vHost) and assign a Munin sensor to each of them. I think there are Munin plugins to monitor virtual hosts directly, but I don't know how they perform. Same for MySQL etc. You can even write your own sensors, it's not that hard.

----------

## selig

Thanks for the tip, I will try Munin and see what it can tell me.

----------

