qq_31825139
2016-07-28 07:38自己写的一个memcache 的小程序,但是总是不能实例化,安装好扩展。求解
<?php
define('DIR',__DIR__);
include DIR .'/Common/Loder.php';
spl_autoload_register('\Common\Loder::autoLoder'); //自动加载类
$database = \Common\Factory::createDatabase('************','root','','memcached_test'); //数据库连接
$memcache = \Common\Factory::addServers('*****',11211); // memcache 服务器地址 端口 如果在这里直接new memcache 是可以的
/**************/
<?php
namespace Common;
class Factory
{
static function createDatabase($localhost, $user, $pwd, $datebase)
{
$db = Register::get($datebase); //从注册器中取出对象
if (!$db) {
$db = new Datebase($localhost, $user, $pwd, $datebase);
Register::set($datebase, $db); //向注册器中注册Datebase
}
return $db;
}
static function addServers($localhost, $port)
{
$key = $localhost.'_me';
$db = Register::get($key); //从注册器中取出对象
if (!$db) {
$db = new Me($localhost,$port);
Register::set($key, $db); //向注册器中注册Me
}
return $db;
}
}
/***************************/
<?php
/**
- Created by PhpStorm.
- User: Administrator
- Date: 2016/7/27
- Time: 18:39 */
namespace Common;
class Me
{
function __construct($localhost,$port)
{
$m = new Memcache(); // 进入这里 浏览器就会报一个 500 的错误
$m->addServer($localhost,$port);
return $m;
}
}
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 如何在小牛队上安装memcache? (MAMP)
- apache
- homebrew
- php
- mamp
- 1个回答
- 使用xampp / php无法使用memcache工作
- xampp
- memcached
- php
- 2个回答
- PHP模块编译API不正确(无法初始化)
- php
- 2个回答
- Memcached安装在MAMP 3.0.3上的PHP 5.3.28上,但不能正常工作
- memcached
- drupal
- php
- mamp
- 3个回答
- 如何添加一个现有的密钥memcache php数据?
- memcached
- php
- 1个回答