I am running a php script locally in my Firefox web browser. After exactly 300 seconds I get an error page. "Problem loading page. The connection has timed out. The server at localhost is taking too long to respond." The script is still running, but it seems extremely slow to me.
Assumption: the Apache Timeout is the cause for the error page (as it is set to 300). But I do not understand why this is happening. It is not the first time that I am running a php script that is taking a long time. Sometimes my scripts run for a few days. This particular script is reading publication data from an InnoDB table (350k records) and splitting the authors by semicolon. These author names are then written back into another table.
Simply increasing the Timeout is not the solution here. I need to fix whatever is causing the timeout. No doubt it is also the reason why my script is running so slow.
I have found the reason for the slow inserts: as I am using InnoDB, I should have wrapped my inserts in a transaction/commit.
And a possible reason for the timeout: specifying 127.0.0.1 in Unix will use TCP/IP instead of a UNIX socket.
On http://httpd.apache.org/docs/2.2/mod/core.html#timeout I can read that "the TimeOut directive defines the length of time Apache will wait for I/O in various circumstances: When reading data from the client, the length of time to wait for a TCP packet to arrive if the read buffer is empty. When writing data to the client, the length of time to wait for an acknowledgement of a packet if the send buffer is full. [...]".
I would be very grateful for any kind of help, such as instructions to look at a certain log file or to run a certain command to get more info. As far as I know, the Apache timeout deals with internet traffic, but I'm not connecting to anything, so... well, I'm lost. Google is no help either.
Some environment information:
- PHP 5.3.10-1ubuntu3.11 with Suhosin-Patch (cli) (built: Apr 4 2014 01:30:04)
- mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2
- Ubuntu 12.04.4 LTS, 3.5.0-51-generic
- FRITZ!Box Fon WLAN 7360, FRITZ!OS 06.04
- LAN 2 at 100 Mbit/s (Green mode, instead of 1 Gbit/s Power mode)
I am using 12.0 GiB of 125.9 GiB memory. No swap. Load average of around 2.3. And still 1.9 TiB available disk space.
What I have tried so far:
- "Work Offline" in my browser
- Go to
127.0.0.1
instead of localhost - In httpd.conf I changed ServerName Localhost to
127.0.0.1:80
- In the php script first retrieve all data, close the resultset and then work from an array.
Whenever I made changes to a config file, I restarted apache2 and mysql.
The php script:
set_time_limit( 0 );
ini_set( 'display_errors', 1 );
ini_set( 'memory_limit', '4G' );
error_reporting( E_ALL|E_STRICT );
$mysqli = new mysqli( 'localhost', 'root', 'mypassword', 'WoS_Mexico_1990-2014' );
if ( $mysqli ) {
$sql = 'SELECT `ID`, `AU`, `AF`, `C1`, `RP`, `EM`, `RI`, `OI` FROM `WoS`;';
if ( $result = $mysqli->query( $sql ) ) {
while ( $row = $result->fetch_assoc() ) {
// do some things such as explode strings into arrays
$sql = 'INSERT INTO ...';
$mysqli->query( $sql );
}
$result->close();
}
$mysqli->close();
}
I have skip-name-resolve in my.cnf.
In a similar topic, someone posted netstat results, so here are mine.
daigu@Jiriki:~$ sudo netstat -plnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 7423/mysqld
tcp 0 0 127.0.0.1:5939 0.0.0.0:* LISTEN 2256/teamviewerd
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2281/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1247/cupsd
tcp6 0 0 :::80 :::* LISTEN 7390/apache2
tcp6 0 0 ::1:631 :::* LISTEN 1247/cupsd
mysqld is on tcp while apache2 is on tcp6. Is that a problem?
Looking in the various log files, I noticed that I am also suffering from UFW spam.
Jun 7 13:34:29 Jiriki kernel: [88803.827685] [UFW BLOCK] IN=eth1 OUT= MAC=01:00:5e:00:00:01:08:96:d7:af:89:26:08:00 SRC=192.168.178.1 DST=224.0.0.1 LEN=36 TOS=0x00 PREC=0xC0 TTL=1 ID=0 DF PROTO=2
daigu@Jiriki:/var/log$ sudo ufw status verbose Status: active Logging: on (low) Default: deny (incoming), allow (outgoing) New profiles: skip
Also the apache2/error.log is quite huge. The last line is:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/http.so' - /usr/lib/php5/20090626/http.so: cannot open shared object file: No such file or directory in Unknown on line 0
[Fri Jun 06 19:32:12 2014] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.11 with Suhosin-Patch configured -- resuming normal operations
But that seems to be an old problem, popping up first on February 16.
The Timeout is not occurring anymore, even though -as far as I know- I have not made any changes to any configuration files.
And to answer Braiam's question: there was nothing in the Apache logs to indicate that there was a misconfiguration. Everything was running just fine, and the php script would in fact continue to run (as it should) even though my browser was showing a Timeout.