diff --git a/README.md b/README.md index 13ccec8..224caab 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,13 @@ composer require csrdelft/orm ``` Before the ORM can be used the cache and database must be initialized. The memcache needs -a writable path and the database and database admin need a host, database, username and +a unix socket or host and port and the database and database admin need a host, database, username and password. After this any model has access to the database. ```php CsrDelft\Orm\Configuration::load([ - 'cache_path' => '/path/to/data/dir', + 'cache_path' => '/path/to/data/dir/cache.socket', // Host or unix socket + 'cache_port' => 11211, // Optional if cache_path is a host 'db' => [ 'host' => 'localhost', 'db' => 'myDatabase', diff --git a/src/Configuration.php b/src/Configuration.php index 897eedb..7be1373 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -34,7 +34,7 @@ public static function load(array $config) { $db_conf = $config['db']; - $ormMemcache = Persistence\OrmMemcache::init($config['cache_path']); + $ormMemcache = Persistence\OrmMemcache::init($config['cache_path'], $config['cache_port'] ?? 0); $dsn = 'mysql:host=' . $db_conf['host'] . ';dbname=' . $db_conf['db']; $options = [ diff --git a/src/Persistence/OrmMemcache.php b/src/Persistence/OrmMemcache.php index 340295c..4b49030 100644 --- a/src/Persistence/OrmMemcache.php +++ b/src/Persistence/OrmMemcache.php @@ -21,11 +21,12 @@ class OrmMemcache extends DependencyManager { /** * OrmMemcache constructor. * @param $path + * @param int $port */ - public function __construct($path) { + public function __construct($path, $port = 0) { if (class_exists('Memcache')) { $this->cache = new Memcache(); - if ($this->cache->connect('unix://' . $path . 'csrdelft-cache.socket', 0)) { + if ($this->cache->connect($path, $port)) { return; } }