Skip to content

Commit

Permalink
Merge pull request #10 from clickalicious/bugfix-general-bugfixing
Browse files Browse the repository at this point in the history
Stability improvements // bugfixes // timeout configurable // documentation
  • Loading branch information
Benjamin Carl committed Feb 15, 2015
2 parents c1a4205 + 26c4b81 commit 6df56fd
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 28 deletions.
18 changes: 18 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,18 @@
filter:
paths: [lib/*]
excluded_paths: [app/*, bin/*, docs/*, tests/*, web/*]
before_commands:
- 'composer install --dev --prefer-source'
tools:
external_code_coverage: true
php_mess_detector: true
php_code_sniffer: true
sensiolabs_security_checker: true
php_code_coverage: true
php_pdepend: true
php_loc:
enabled: true
excluded_dirs: [docs, tests, bin]
php_cpd:
enabled: true
excluded_dirs: [docs, tests, bin]
8 changes: 6 additions & 2 deletions .travis.yml
Expand Up @@ -14,14 +14,19 @@ before_install:
- composer self-update

before_script:
- composer install --prefer-source
- composer install --dev --prefer-source
- composer --optimize-autoloader
- mkdir -p ./build/logs

script:
- phpunit --configuration tests/phpunit.xml --coverage-clover ./build/logs/clover.xml

after_script:
- php vendor/bin/coveralls
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --access-token=$SCRUTINIZERKEY --format=php-clover ./build/logs/clover.xml > /dev/null 2>&1

after_success:
# CREATE GIT TAG
- git config --global user.email "builds@travis-ci.org"
- git config --global user.name "Travis"
Expand All @@ -41,4 +46,3 @@ matrix:
fast_finish: true
allow_failures:
- php: hhvm

7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -37,7 +37,7 @@ The recommended way to install this tool is through [Composer](http://getcompose
```json
{
"require": {
"clickalicious/phpmemadmin": "~0.1"
"clickalicious/phpmemadmin": "~0.4"
},
"scripts": {
"post-install-cmd": [
Expand All @@ -47,7 +47,7 @@ The recommended way to install this tool is through [Composer](http://getcompose
}
```

**Important!** The postInstall call is important - it installs all required files and shows you an example vhost configuration for your installation. So be sure to add it to the `composer.json` (as shown above) before you call `composer install`.
**Important!** The postInstall call is important - it installs all required files and shows you an example vhost configuration for your installation. So be sure to add it to the `composer.json` (as shown above) before you call `composer install`. phpMemAdmin requires at least v0.4.0 of Memcached.php!

**phpMemAdmin** is also available as [download from github packed as zip-file](https://github.com/clickalicious/phpMemAdmin/archive/master.zip "zip package containing library for download") or via `git clone https://github.com/clickalicious/phpMemAdmin.git .`

Expand All @@ -58,6 +58,7 @@ After install is completed you will find a configuration file called `.config.di
{
"username": "admin",
"password": "pass",
"timeout": -1,
"cluster": {
"name": "Cluster",
"thresholds": {
Expand Down Expand Up @@ -119,6 +120,8 @@ For a consistent versioning i decided to make use of `Semantic Versioning 2.0.0`

## Roadmap

- [ ] General stability improvements and tests
- [ ] Realtime statistics
- [ ] Move all assets from CDN to local filesystem as precondition for compiling everything into a single file app (requires an issue).
- [ ] Move "settings" from dashboard to an own page
- [ ] Add more checks to cluster health check
Expand Down
1 change: 1 addition & 0 deletions app/.config.dist
@@ -1,6 +1,7 @@
{
"username": "admin",
"password": "pass",
"timeout": -1,
"cluster": {
"name": "Cluster",
"thresholds": {
Expand Down
2 changes: 1 addition & 1 deletion app/templates/403.tpl
@@ -1,6 +1,6 @@
<html xmlns="http://www.w3.org/1999/html">
<head>
<title>Test</title>
<title>phpMemAdmin</title>
</head>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"clickalicious/memcached.php": "~0.1",
"clickalicious/memcached.php": "~0.4",
"wp-cli/php-cli-tools": "~0.10"
},
"require-dev": {
Expand Down
39 changes: 25 additions & 14 deletions lib/Clickalicious/PhpMemAdmin/App.php
Expand Up @@ -862,7 +862,7 @@ protected function processRequestOperations($action, array $arguments)
$value = $this->castAsPhpType($arguments['value']);

if (true !== $result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->set($arguments['set'], $value)
) {
$error = $this->errorContext(
Expand Down Expand Up @@ -890,7 +890,7 @@ protected function processRequestOperations($action, array $arguments)
$value = $this->castAsPhpType($arguments['value']);

if (true !== $result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->replace($arguments['replace'], $value)
) {
$error = $this->errorContext(
Expand All @@ -906,7 +906,7 @@ protected function processRequestOperations($action, array $arguments)
$arguments['append'] = strip_tags($arguments['append'])
) {
if (true !== $result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->append($arguments['append'], $arguments['value'])
) {
$error = $this->errorContext(
Expand All @@ -922,7 +922,7 @@ protected function processRequestOperations($action, array $arguments)
$arguments['prepend'] = strip_tags($arguments['prepend'])
) {
if (true !== $result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->prepend($arguments['prepend'], $arguments['value'])
) {
$error = $this->errorContext(
Expand All @@ -940,7 +940,7 @@ protected function processRequestOperations($action, array $arguments)
$value = $this->castAsPhpType($arguments['value']);

if (true !== is_float($result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->incr($arguments['increment'], $value))
) {
$error = $this->errorContext(
Expand All @@ -959,7 +959,7 @@ protected function processRequestOperations($action, array $arguments)
$value = $this->castAsPhpType($arguments['value']);

if (true !== is_float($result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->decr($arguments['decrement'], $value))
) {
$error = $this->errorContext(
Expand All @@ -976,7 +976,7 @@ protected function processRequestOperations($action, array $arguments)
$arguments['delete'] = strip_tags($arguments['delete'])
) {
if (true !== $result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->delete($arguments['delete'])
) {
$error = $this->errorContext(
Expand All @@ -989,7 +989,7 @@ protected function processRequestOperations($action, array $arguments)
$arguments['flush'] = strip_tags($arguments['flush'])
) {
if (true !== $result = $this
->getMemcachedClient($host[0], $host[1])
->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout)
->flush()
) {
$error = $this->errorContext(
Expand Down Expand Up @@ -1163,14 +1163,15 @@ protected function getMessages()
/**
* Returns an instance of Client for host and port combination.
*
* @param string $host The host to return instance for
* @param int $port The port to return instance for
* @param string $host The host to return instance for
* @param int $port The port to return instance for
* @param int $timeout The timeout used when connecting
*
* @author Benjamin Carl <opensource@clickalicious.de>
* @return \Clickalicious\Memcached\Client A client instance
* @access protected
*/
protected function getMemcachedClient($host, $port = Client::DEFAULT_PORT)
protected function getMemcachedClient($host, $port = Client::DEFAULT_PORT, $timeout = null)
{
$uuid = $this->uuid($host, $port);
$clients = $this->getClients();
Expand All @@ -1183,6 +1184,12 @@ protected function getMemcachedClient($host, $port = Client::DEFAULT_PORT)
->host($host)
->port($port);

// Check for custom timeout (maybe required when connecting outside localhost = more latency)
if (null !== $timeout && true === is_int($timeout) && $timeout >= 0) {
$client
->timeout($timeout);
}

$clients[$uuid] = $client;
$this->setClients($clients);
} else {
Expand Down Expand Up @@ -2095,7 +2102,7 @@ protected function getHtmlNavigationEntry($action, $title, $glyphicon = '')
protected function getSettings($host)
{
$host = explode(':', $host);
$client = $this->getMemcachedClient($host[0], $host[1]);
$client = $this->getMemcachedClient($host[0], $host[1], $this->getConfig()->timeout);

return $client->stats(CLIENT::STATS_TYPE_SETTINGS);
}
Expand All @@ -2117,7 +2124,11 @@ protected function aggregateStatistics(array $hosts = array())
// Passed host(s) to this method
foreach ($hosts as $host) {
$currentHost = explode(':', $host);
$client = $this->getMemcachedClient($currentHost[0], $currentHost[1]);
$client = $this->getMemcachedClient(
$currentHost[0],
$currentHost[1],
$this->getConfig()->timeout
);
$statistics[$host] = $client->stats();
}

Expand Down Expand Up @@ -2259,7 +2270,7 @@ protected function dumpEntries($host, $port, $namespace = null, $flat = false)
// Assume empty result
$result = array();

$client = $this->getMemcachedClient($host, $port);
$client = $this->getMemcachedClient($host, $port, $this->getConfig()->timeout);

// Fetch all keys and all values ...
$allSlabs = $client->stats(Client::STATS_TYPE_SLABS);
Expand Down
15 changes: 7 additions & 8 deletions web/index.php
Expand Up @@ -55,18 +55,18 @@
$path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

define(
'CLICKALICIOUS_PHPMEMADMIN_BASE_PATH',
$path
'CLICKALICIOUS_PHPMEMADMIN_BASE_PATH',
$path
);

// Is composer setup we're running in?
if (true === file_exists('../vendor/autoload.php')) {
include_once '../vendor/autoload.php';
include_once '../vendor/autoload.php';

} else {
set_include_path(
get_include_path() . PATH_SEPARATOR . $path
);
set_include_path(
get_include_path() . PATH_SEPARATOR . $path
);
}

// Bootstrapping is just error handling and stuff like that ...
Expand All @@ -92,8 +92,7 @@
*/
$app = new \Clickalicious\PhpMemAdmin\App(
$config,
new \Clickalicious\Memcached\Client(), //\\ Memcached.php client as master to clone
'/Projekte/phpMemAdmin/web/'
new \Clickalicious\Memcached\Client() //\\ Memcached.php client as master to clone
);

/**
Expand Down

0 comments on commit 6df56fd

Please sign in to comment.