Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
Allow memcache to connect to a host/port
Browse files Browse the repository at this point in the history
  • Loading branch information
qurben committed Mar 5, 2020
1 parent 31e3cf5 commit ec8b8d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
5 changes: 3 additions & 2 deletions src/Persistence/OrmMemcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit ec8b8d1

Please sign in to comment.