I am connecting to a remote mongodb host with the PHP class mongoclient.
I have not written anything simple but simple connection code.
$connection_url = "mongodb://{$dbuser}:{$dbpass}@{$dburl}:{$dbport}/{$dbname}";
$this->m = new MongoClient($connection);
It connects to mongodb, but after a while my application freezes. By freezing, I mean running php sript forever, no response, and finally apache and my server. I need to restart my server so that it reappears.
Why does the PHP script work forever and mongoserver is not responding.
I have max_execution_timeset the value to 30 seconds.
MongoClient Version 1.4.5
Update:
As explained here
By default, the connection and timeout of the socket from mongodb is never timeout , I think maybe php MongoClient will wait forever if the socket is closed by MongoServer.
To make sure that I have set the parameters for mongoclient, so as not to wait more than 5 seconds if the socket is closed, for example below
$connection_url = "mongodb://{$dbuser}:{$dbpass}@{$dburl}:{$dbport}/{$dbname}";
$options = array('connectTimeoutMS' =>5000 , 'socketTimeoutMS' => 5000);
$this->m = new MongoClient($connection, $options);
But it's still hanging
Here is a short Mongo Log
2: 4: somehost connection found; -; dbname / user / fd6da21ee7cf37731eb88e250d4a05d6; 1957 (looking for somehost; -; dbname / username / fd6da21ee7cf37731eb88e250d4a05d6; 1957) 2: 2: mongo_get_read_write_connection: search for a connection STANDALONE
2: 4: host connection found; -; dbname / username / fd6da21ee7cf37731eb88e250d4a05d6; 1957 (looking for hostname; -; dnname / user / fd6da21ee7cf37731eb88e250d4a05d6; 1957)
2: 2: is_ping: pinging ; -; _/ /fd 6da21ee7cf37731eb88e250d4a05d6, 1957
'is_ping'. , script .
Update:
,
ps aux | sort -rk 3,3 | head -n 20
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
www-data 32612 0.0 1.1 108372 5604 ? S 11:05 0:00 /usr/sbin/apache2 -k start
www-data 32390 0.0 1.1 108372 5604 ? S 11:04 0:00 /usr/sbin/apache2 -k start
www-data 32389 0.0 1.4 109192 7348 ? S 11:00 0:00 /usr/sbin/apache2 -k start
www-data 32388 0.0 1.4 109192 7376 ? S 11:00 0:00 /usr/sbin/apache2 -k start
www-data 32387 0.0 1.4 109192 7376 ? S 11:00 0:00 /usr/sbin/apache2 -k start
www-data 32386 0.0 1.2 108412 6100 ? S 11:00 0:00 /usr/sbin/apache2 -k start
www-data 32385 0.0 1.8 111692 9432 ? S 11:00 0:00 /usr/sbin/apache2 -k start
www-data 31833 0.0 1.5 109216 7548 ? S 02:35 0:00 /usr/sbin/apache2 -k start
www-data 31173 0.0 1.5 108824 7872 ? S Mar02 0:00 /usr/sbin/apache2 -k start
www-data 15538 0.0 1.5 109216 7664 ? S Mar02 0:00 /usr/sbin/apache2 -k start
www-data 15536 0.0 1.4 109200 7496 ? S Mar02 0:00 /usr/sbin/apache2 -k start
www-data 15535 0.0 1.6 110904 8444 ? S Mar02 0:00 /usr/sbin/apache2 -k start
www-data 15534 0.0 1.3 108684 6536 ? S Mar02 0:00 /usr/sbin/apache2 -k start
whoopsie 847 0.0 0.5 187668 2676 ? Ssl Feb24 0:00 whoopsie
syslog 370 0.0 0.6 249676 3060 ? Sl Feb24 0:31 rsyslogd -c5
root 984 0.0 0.1 15792 908 tty1 Ss+ Feb24 0:00 /sbin/getty -8 38400 tty1
root 946 0.0 2.0 108348 10120 ? Ss Feb24 0:32 /usr/sbin/apache2 -k start
root 9 0.0 0.0 0 0 ? S Feb24 0:00 [rcu_bh]
root 879 0.0 0.0 0 0 ? S< Feb24 0:00 [kvm-irqfd-clean]