PHP Classes
elePHPant
Icontem

PHP Cache Server: Store and retrieve cached data in a network server

Recommend this page to a friend!
  Info   View files Documentation   View files View files (39)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-09-17 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 154 This week: 1All time: 8,575 This week: 411Up
Version License PHP version Categories
phpcache 1.1.1GNU General Publi...7.2Networking, PHP 5, Databases, Cache, P...
Description Author

This package can store and retrieve cached data in a network server.

It can work as a client and a server that takes TCP connection requests and can store and retrieve data a in a cache container.

The client may request to store, retrieve and delete data in a cache container on the server by sending a request over a TCP connection.

The server handles the TCP request by executing the requested cache operation using arrays as storage container.

Innovation Award
PHP Programming Innovation award winner
July 2018
Winner
There are several products that allow caching data very quickly and can be accessed via a local network connection.

This package can work as a client and server to store data a in a cache container that uses PHP arrays in memory for fast cache data access.

Manuel Lemos
  Performance   Level  
Name: Krisztián Dudás <contact>
Classes: 1 package by
Country: Hungary Hungary
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Details

StyleCI Scrutinizer Code Quality Build Status

php-cache

Cache implementation for php

Usage:

Prequests:

  • PHP 5/7
  • composer #### Installing via composer: ` composer require kdudas/php-cache ` #### Supperted data types:
  • String
  • Integer/Float/Double
  • Array
  • Objects #### Creating a new server instance ` <?php

ini_set('log_errors', 1); ini_set('error_log', '/var/log/php-cache.log'); require_once 'vendor/autoload.php';

use PhpCache\CacheServer\CacheServer; use PhpCache\ServiceManager\ConfigAggregator; use PhpCache\ServiceManager\ServiceManager; // You can import multiple config files to overwrite parameters in the basic config or add extra parameters, including dependency injection $config = include_once 'config.php'; $configAggregator = new ConfigAggregator(); $configAggregator->addConfig($config); $serviceManager = new ServiceManager($configAggregator->getMergedConfig()); $server = $serviceManager->get(CacheServer::class); $server->run();

#### Running the server:

php testServer.php

#### OR

mv daemon.sh /etc/init.d/php-cache chmod +x /etc/init.d/php-cache

now you can use systemctl style service management

sudo service php-cache start

##### Note: you can modify the contents of `daemon.sh` if you want to use other directories
#### Configuration array:
- `config`: Basic configuration array  
-- `memoryLimit`: as the name suggests, after we exceed the limit, our data in the cache pool gets backed up to file system  
-- `location`: server IP address or socket file location (string)  
-- `port`: the port to run the sockets on (number)  
-- `bufferSize`: how big chunks of data is being read from a stream (bytes)  
-- `ttl`: time to live; how long an entry should take space up in the cache pool before being deleted (seconds)  
-- `backupTime`: schedule backups (seconds)  
-- `backupDir`: where to store backed up data? A backup is made when we are shutting down the server service, when the scheduled backup occures or our cache pool exceeded it's memory limit  
-- `socketType`: which socket type should we use? Open a port on the network for the socket or create a file for the socket. Values must be either `file` (`CacheIOHandler::SOCKET_TYPE_FILE`) or `ip` (`CacheIOHandler::SOCKET_TYPE_IP`)  
- `services`: service manager configuration  
-- `aliases`: a name assigned for a real service (Example: `'cache-server' => CacheServer::class`)  
-- `factories`: service name with factory name for service pairs  
-- `invokables`: services with no dependencies  

#### Creating a new client instance

<?php include_once('vendor/autoload.php');

use PhpCache\CacheClient\CacheClient; use PhpCache\ServiceManager\ServiceManager;

$config = require_once 'config.php'; $serviceManager = new ServiceManager($config); /@var $client CacheClient/ $client = $serviceManager->get(CacheClient::class); $client->set('test', 'ASD'); echo $client->get('test');

##### You can run the client either from browser or console

php testClient.php

#### CLI Commands:
`./phpCache get <key>` gets entries for the specified key. If no key is specified, it returns all entries.  
`./phpCache set <key> <value>` pushes an entry to the cache pool with the given key - value pair.  
`./phpCache delete <key>` deletes the entry with the given key
  Files folder image Files  
File Role Description
Files folder image.phan (1 file)
Files folder imagesrc (7 directories)
Plain text file composer.json Data Auxiliary data
Plain text file composer.lock Data Auxiliary data
Plain text file config.php Conf. Configuration script
Plain text file daemon.sh Data Auxiliary data
Plain text file LICENSE Lic. License text
Plain text file parallel_commands.sh Data Script to create parallel connections to server socket (for stress testing purposes)
Plain text file pharBuilder.php Example Example script
Plain text file phpCache Example Example script
Plain text file README.md Doc. Documentation
Plain text file testClient.php Example Class source
Plain text file testServer.php Example Class source

  Files folder image Files  /  .phan  
File Role Description
  Plain text file config.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageCacheClient (3 files)
Files folder imageCacheEventListener (2 files)
Files folder imageCacheServer (4 files)
Files folder imageCommands (4 files)
Files folder imageIO (2 files, 1 directory)
Files folder imageServiceManager (3 files, 1 directory)
Files folder imageStorage (5 files, 1 directory)

  Files folder image Files  /  src  /  CacheClient  
File Role Description
  Plain text file CacheClient.php Class Class source
  Plain text file CacheClientFactory.php Class Class source
  Plain text file ClientInterface.php Class Class source

  Files folder image Files  /  src  /  CacheEventListener  
File Role Description
  Plain text file CacheEventListenerInterface.php Class Class source
  Plain text file CacheEventListenerInterface.php Class Class source

  Files folder image Files  /  src  /  CacheServer  
File Role Description
  Plain text file ActionHandler.php Class Class source
  Plain text file CacheServer.php Class Class source
  Plain text file CacheServerFactory.php Class Class source
  Plain text file CacheServerInterface.php Class Class source

  Files folder image Files  /  src  /  Commands  
File Role Description
  Plain text file DeleteCommand.php Class Added console comma
  Plain text file GetCommand.php Class Added console comma
  Plain text file QuitCommand.php Class Class source
  Plain text file SetCommand.php Class Added console comma

  Files folder image Files  /  src  /  IO  
File Role Description
Files folder imageException (2 files)
  Plain text file CacheIOHandler.php Class Class source
  Plain text file CacheIOHandlerFactory.php Class Class source

  Files folder image Files  /  src  /  IO  /  Exception  
File Role Description
  Plain text file InvalidConfigException.php Class Class source
  Plain text file IOException.php Class Class source

  Files folder image Files  /  src  /  ServiceManager  
File Role Description
Files folder imageException (1 file)
  Plain text file ConfigAggregator.php Class Class source
  Plain text file ConfigAggregator.php Class Class source
  Plain text file ServiceManager.php Class Dependency injection logic

  Files folder image Files  /  src  /  ServiceManager  /  Exception  
File Role Description
  Plain text file NotFoundException.php Class Class source

  Files folder image Files  /  src  /  Storage  
File Role Description
Files folder imageException (1 file)
  Plain text file Bucket.php Class Class source
  Plain text file BucketFactory.php Class Class source
  Plain text file Maintainer.php Class Class source
  Plain text file MaintainerFactory.php Class Class source
  Plain text file StorageInterface.php Class Class source

  Files folder image Files  /  src  /  Storage  /  Exception  
File Role Description
  Plain text file StorageException.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:154
This week:1
All time:8,575
This week:411Up