问题
I just started using Redis in my application, but for some reason the initial connection to the Redis server from PHP takes almost exactly 1 second. When using Predis, the latency issue doesn't occur until the first get()
call, and if I try connecting manually the latency occurs on the initial connection via fsockopen()
.
I've read the redis latency documentation, but none of the information seemed relevant to my case. Running redis-cli --latency
just seemed to product a garbled mess. I guess my question is what's the best way to troubleshoot this? Any help would be much appreciated.
Predis Client instantiation:
$redis = new Predis\Client(array(
'host' => 'localhost',
'port' => 6379
));
Here's some relevant info:
- PHP 5.4.7
- XAMPP
- Windows 7 64-bit
- 16GB ram
- The redis server is running locally on port 6379
回答1:
On windows always use 127.0.0.1
instead of localhost.
In recent versions of windows resolution of name localhost
is handled within DNS itself (it is a "feature" to help incorporate IPv6) and this dns query always take 1 sec.
来源:https://stackoverflow.com/questions/14076403/redis-connection-slow-from-php