|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-07-16 13:45 UTC] andrei@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 20:00:01 2025 UTC |
Description: ------------ A simple script that sets a value and the retrieves it is included below called memcached.php. There are no open connections to the memcached server running locally on port 11211: $ netstat -an | grep ESTABLISHED | awk '{print $5}' | grep 11211 |wc -l 0 Add some load to the script with apachebench: $ ab -n2000 -c10 "http://localhost/memcached.php" There are a huge number of open connections to the memcached server: $ netstat -an | grep ESTABLISHED | awk '{print $5}' | grep 11211 |wc -l 1003 A sample netstat line is included here: tcp 0 0 127.0.0.1:41306 127.0.0.1:11211 ESTABLISHED These connections do not dissipate and quickly overwhelm whatever the max connections limit is on memcached, causing the script to hang. For example, this is the output when apachebench is run a second time immediately after the first run: $ ab -n2000 -c10 "http://localhost/memcached.php" This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) apr_poll: The timeout specified has expired (70007) Total of 44 requests completed After a restart of memcached, with no other users of the memcached server and running the ab command above twice, the memcached server shows these stats: STAT total_connections 1035 STAT connection_structures 1018 Apache is running with MPM prefork and MaxClients 150. Reproduce code: --------------- <?php $key = "key_" . uniqid(); $memcached = new Memcached('persistent'); $memcached->addServer('localhost', 11211); $memcached->set($key, 'value'); $value = $memcached->get($key); echo $value; // prints "value" when loaded in a browser Expected result: ---------------- A small number of connections are established and reused.