E:\phpStudy\Apache\bin>ab -c1000 -n10000 http://localhost/mysql.php
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.4.10
Server Hostname: localhost
Server Port: 80
Document Path: /mysql.php
Document Length: 242 bytes
Concurrency Level: 1000
Time taken for tests: 39.351 seconds
Complete requests: 10000
Failed requests: 9
(Connect: 9, Receive: 0, Length: 0, Exceptions: 0)
Total transferred: 4440000 bytes
HTML transferred: 2420000 bytes
Requests per second: 254.12 [#/sec] (mean)
Time per request: 3935.125 [ms] (mean)
Time per request: 3.935 [ms] (mean, across all concurrent requests)
Transfer rate: 110.19 [Kbytes/sec] received
==========================以上的MYSQL,以下是REDIS===============================
E:\phpStudy\Apache\bin>ab -c1000 -n10000 http://localhost/redis.php
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
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)
Completed 1000 requests
Test aborted after 10 failures
apr_socket_connect(): 由于目标计算机积极拒绝,无法连接。 (730061)
Total of 1714 requests completed
MYSQL可以跑,REDIS很快就挂掉了,下面是代码
$host = 'mysql:host=127.0.0.1;dbname=test';
$user = 'root';
$pass = 'root';
$pdo = new PDO($host, $user, $pass);
var_dump($pdo->query('select * from table where id = 1')->fetch());die;
==========================以上的MYSQL,以下是REDIS===============================
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('test','testvalue');
var_dump($redis->get('test'));
$redis->delete('test');
Redis官方并不支持Windows,Windows版本Redis貌似是微软自己移植的东西,不稳定也很正常.所以说,测试还是放到Linux上来.就PHP而言,同一机器,Windows+Ubuntu双系统,同一PHP版本,Ubuntu上PHP就要比Windows上快.
还有,Windows上Apache的winnt MPM是一个多线程MPM,并发大生成的线程数也多,过多的PHP连接Redis可能也是Redis挂掉的原因.所以你可以考虑减少并固定Apache线程数(比如10个线程),ab并发时降低到100,PHP开启到Redis的持久连接.