查看memcached/redis/pdo_mysql/phpinfo是否正确配置

2017-07-17 by zhezhebie

<?phpecho '<h1>测试memcached连接</h1>';$m = new Memcached();$con = $m->addServer('127.0.0.1', 11211);if ($con) { $m->set('int', '999', 60); $m->set('string', 'a simple string'); $m->set('array', array(11, 12)); /* 'object'这个key将在5分钟后过期 */ $m->set('object', new stdclass, 300); var_dump($m->get('int')); echo "<hr>"; var_dump($m->get('string')); echo "<hr>"; echo "<pre>"; print_r($m->get('array')); echo "</pre>"; echo "<hr>"; var_dump($m->get('object')); echo "<hr>"; # code...} else { die('Could not connect to the memcached');}echo '<h1>测试redis连接</h1>';$redis = new Redis();$con = $redis->connect('127.0.0.1', 6379);if ($con) { echo "Connection to server sucessfully"; $redis->set("tutorial-name", "Redis tutorial"); echo "Stored string in redis:: " . $redis->get("tutorial-name");} else { die('Could not connect to the redis');}//set the data in redis string// Get the stored data and print itecho '<h1>测试pdo_mysql连接</h1>';$dsn = 'mysql:dbname=mysql;host=192.168.1.xxx;port=3306';$username = 'root';$password = 'xxxx';try { $pdo = new PDO($dsn, $username, $password); $pdo->exec('set names utf8'); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);} catch (PDOException $e) { die('Could not connect to the database:' . $e);}$statement = "select * from user";$rows = $pdo->query($statement);print_r($rows->rowCount());foreach ($rows->FetchAll() as $row) { echo "<pre>"; print_r($row); echo "</pre>";}phpinfo();

最新更新:

第七城市

栏目导航(关闭)