Skip to content

Commit

Permalink
Merge pull request #50 from artur-graniszewski/develop
Browse files Browse the repository at this point in the history
Release of 1.7.1
  • Loading branch information
artur-graniszewski committed May 4, 2017
2 parents c0e1d13 + fce3aee commit 91dde6f
Show file tree
Hide file tree
Showing 68 changed files with 1,088 additions and 1,876 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog

## Version 1.7.1
- [Improvement] Removed ReactPHP library from ZEUS Memcached Server and replaced it with ZEUS socket server implementation
- [Improvement] Removed ReactPHP library from ZEUS Async Server and replaced it with ZEUS socket server implementation
- [Improvement] Removed ReactPHP library from required packages in Composer configuration
- [Improvement] Various stability and performance improvements in Fifo IPC Adapter (now using ZEUS socket implementation)
- [Improvement] Moved ZEUS socket code to Kernel namespace (as a new Networking layer)
- [Fix] Fixed Async Controller Plugin not honoring join timeout settings (could hang indefinitely on stale socket connection)
- [Fix] Improved detection if client disconnected in ZEUS networking layer (workaround for PHP socket inconsistency)

## Version 1.7.0
- [Feature] New low level, high-speed ZEUS socket server implementation usable by any network-enabled Server Service
- [Improvement] Removed ReactPHP library from ZEUS Web Server and replaced it with ZEUS socket server implementation
Expand Down
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -80,7 +80,7 @@ Output:
2017-04-15 14:10:48.772 INFO 24904 --- [ main] ernel\IpcServer\Factory\IpcServerFactory : Using Zeus\Kernel\IpcServer\Adapter\FifoAdapter for zeus_httpd IPC
2017-04-15 14:10:48.773 INFO 24904 --- [ main] ernel\IpcServer\Factory\IpcServerFactory : Enumerating IPC capabilities:
2017-04-15 14:10:48.773 INFO 24904 --- [ main] ernel\IpcServer\Factory\IpcServerFactory : IPC message size limit: 65536 bytes
2017-04-15 14:10:48.783 INFO 24904 --- [ zeus_httpd] ervice\Shared\AbstractReactServerService : Launching server on 0.0.0.0:7070
2017-04-15 14:10:48.783 INFO 24904 --- [ zeus_httpd] rvice\Shared\AbstractSocketServerService : Launching server on 0.0.0.0:7070
2017-04-15 14:10:48.786 INFO 24904 --- [ zeus_httpd] Zeus\Kernel\ProcessManager\Scheduler : Starting Scheduler with 1 plugin
2017-04-15 14:10:48.795 INFO 24905 --- [ zeus_httpd] Zeus\Kernel\ProcessManager\Scheduler : Establishing IPC
2017-04-15 14:10:48.795 INFO 24905 --- [ zeus_httpd] Zeus\Kernel\ProcessManager\Scheduler : Scheduler started
Expand Down Expand Up @@ -337,7 +337,6 @@ Percentage of the requests served within a certain time (ms)
## Library requirements
- Zend Framework 3+ application (with the following modules installed: `zend-mvc`, `zend-mvc-console`, `zend-console`, `zend-log`, `zend-config`)
- Opis library (`opis/closure`)
- ReactPHP library

# Installation

Expand Down Expand Up @@ -396,7 +395,7 @@ user@host:/var/www/zf-application/public$ php index.php zeus status zeus_httpd
### Web Server
- Code refactor and HTTP performance improvements
- Performance improvements in Application dispatcher when handling Zend Framework applications
- Removing dependency on ReactPHP
- (implemented) ~~Removing dependency on ReactPHP~~
- More configuration options

### Inter-Process Communication
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Memcached/MemcachedMessageBenchmark.php
Expand Up @@ -5,7 +5,7 @@
use Athletic\AthleticEvent;
use Zend\Cache\Storage\Adapter\Memory;
use Zeus\ServerService\Memcache\Message\Message;
use ZeusTest\Helpers\ReactTestConnection;
use ZeusTest\Helpers\SocketTestConnection;

class MemcachedMessageBenchmark extends AthleticEvent
{
Expand All @@ -16,7 +16,7 @@ class MemcachedMessageBenchmark extends AthleticEvent

public function setUp()
{
$this->connection = new ReactTestConnection();
$this->connection = new SocketTestConnection(null);
$this->message = new Message(new Memory(), new Memory());
$this->message->onOpen($this->connection);
$this->send("set test-key 12121212 10 2\r\nOK\r\n");
Expand Down
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -42,7 +42,6 @@
"zendframework/zend-console": "^2.6",
"zendframework/zend-config": "^2.6",
"zendframework/zend-mvc-console": "^1.1",
"react/react": "^0.4.2",
"zendframework/zend-log": "^2.9",
"opis/closure": "^2.4.0"
},
Expand Down
3 changes: 2 additions & 1 deletion config/console.router.config.php
@@ -1,6 +1,7 @@
<?php

use Zeus\Controller\ConsoleController;
use Zeus\Controller\ProcessController;

return [
'routes' => [
Expand All @@ -11,6 +12,6 @@
'controller' => ConsoleController::class
]
]
]
],
]
];
10 changes: 4 additions & 6 deletions config/module.config.php
Expand Up @@ -3,11 +3,11 @@
namespace Zeus;

use Zeus\Controller\ConsoleController;
use Zeus\Controller\Factory\ConsoleControllerFactory;
use Zeus\Controller\Factory\ControllerFactory;
use Zeus\Kernel\IpcServer\Adapter\IpcAdapterInterface;
use Zeus\Kernel\IpcServer\Factory\IpcAdapterAbstractFactory;
use Zeus\Kernel\IpcServer\Factory\IpcServerFactory;
use Zeus\Kernel\ProcessManager\MultiProcessingModule\Factory\PosixProcessFactory;
use Zeus\Kernel\ProcessManager\MultiProcessingModule\Factory\MultiProcessingModuleFactory;
use Zeus\Kernel\ProcessManager\MultiProcessingModule\PosixProcess;
use Zeus\ServerService\Async\AsyncPlugin;
use Zeus\ServerService\Async\Factory\AsyncPluginFactory;
Expand All @@ -20,7 +20,6 @@
use Zeus\ServerService\Manager;
use Zeus\Kernel\ProcessManager\Scheduler;
use Zeus\Kernel\ProcessManager\Process;
use Zeus\ServerService\Http\Factory\RequestFactory;
use Zeus\ServerService\Memcache\Factory\MemcacheFactory;
use Zeus\ServerService\Shared\Factory\AbstractServerServiceFactory;
use Zeus\ServerService\Shared\Logger\IpcLoggerFactory;
Expand All @@ -38,7 +37,7 @@

],
'factories' => [
ConsoleController::class => ConsoleControllerFactory::class,
ConsoleController::class => ControllerFactory::class,

]
],
Expand All @@ -59,10 +58,9 @@
Scheduler::class => SchedulerFactory::class,
Process::class => ProcessFactory::class,
Manager::class => ManagerFactory::class,
PosixProcess::class => PosixProcessFactory::class,
PosixProcess::class => MultiProcessingModuleFactory::class,
LruDiscipline::class => LruDisciplineFactory::class,
MemcacheService::class => MemcacheFactory::class,
//Service::class => ServiceFactory::class,
],
'abstract_factories' => [
IpcAdapterAbstractFactory::class,
Expand Down
45 changes: 0 additions & 45 deletions docs/book/apigility-example.md
Expand Up @@ -43,51 +43,12 @@ Installing Zend\Log from package zendframework/zend-log
- Installing evenement/evenement (v2.0.0)
Loading from cache
- Installing react/stream (v0.4.6)
Loading from cache
- Installing react/promise (v2.5.0)
Loading from cache
- Installing react/event-loop (v0.4.2)
Loading from cache
- Installing react/socket (v0.4.6)
Loading from cache
- Installing react/promise-timer (v1.1.1)
Downloading: 100%
- Installing react/cache (v0.4.1)
Loading from cache
- Installing react/dns (v0.4.6)
Downloading: 100%
- Installing react/socket-client (v0.4.6)
Loading from cache
- Installing psr/http-message (1.0.1)
Loading from cache
- Installing ringcentral/psr7 (1.2.1)
Loading from cache
- Installing react/http (v0.4.4)
Loading from cache
- Installing guzzlehttp/psr7 (1.4.1)
Downloading: 100%
- Installing react/http-client (v0.4.16)
Downloading: 100%
- Installing react/child-process (v0.4.3)
Downloading: 100%
- Installing react/react (v0.4.2)
Loading from cache
- Installing zendframework/zend-text (2.6.0)
Loading from cache
Expand All @@ -101,12 +62,6 @@ Installing Zend\Mvc\Console from package zendframework/zend-mvc-console
zendframework/zend-log suggests installing ext-mongo (mongo extension to use Mongo writer)
zendframework/zend-log suggests installing ext-mongodb (mongodb extension to use MongoDB writer)
zendframework/zend-log suggests installing zendframework/zend-mail (Zend\Mail component to use the email log writer)
react/event-loop suggests installing ext-libevent (>=0.1.0)
react/event-loop suggests installing ext-event (~1.0)
react/event-loop suggests installing ext-libev (*)
react/react suggests installing ext-libevent (Allows for use of a more performant event-loop implementation.)
react/react suggests installing ext-libev (Allows for use of a more performant event-loop implementation.)
react/react suggests installing ext-event (Allows for use of a more performant event-loop implementation.)
Writing lock file
Generating autoload files
```
Expand Down
1 change: 0 additions & 1 deletion docs/book/installation.md
Expand Up @@ -13,7 +13,6 @@
### Library requirements
- Zend Framework 3+ application (with the following modules installed: `zend-mvc`, `zend-mvc-console`, `zend-console`, `zend-log`, `zend-config`)
- Opis library (`opis/closure`)
- ReactPHP library

# Installation

Expand Down
Expand Up @@ -11,7 +11,7 @@
use Zeus\ServerService\Manager;
use Zeus\ServerService\Shared\Logger\LoggerInterface;

class ConsoleControllerFactory implements FactoryInterface
class ControllerFactory implements FactoryInterface
{
/**
* Create an object
Expand Down
67 changes: 33 additions & 34 deletions src/Zeus/Kernel/IpcServer/Adapter/FifoAdapter.php
Expand Up @@ -5,6 +5,8 @@
use Zeus\Kernel\IpcServer\Adapter\Helper\MessagePackager;
use Zeus\Kernel\IpcServer\MessageSizeLimitInterface;
use Zeus\Kernel\IpcServer\NamedLocalConnectionInterface;
use Zeus\Kernel\Networking\FlushableConnectionInterface;
use Zeus\Kernel\Networking\FileStream;

/**
* Class FifoAdapter
Expand All @@ -18,7 +20,7 @@ final class FifoAdapter implements
{
use MessagePackager;

/** @var resource[] sockets */
/** @var FileStream[] sockets */
protected $ipc = [];

/** @var string */
Expand Down Expand Up @@ -76,10 +78,12 @@ public function connect()
posix_mkfifo($fileName1, 0600);
posix_mkfifo($fileName2, 0600);

$this->ipc[0] = fopen($fileName1, "r+"); // ensures at least one writer (us) so will be non-blocking
$this->ipc[1] = fopen($fileName2, "r+"); // ensures at least one writer (us) so will be non-blocking
stream_set_blocking($this->ipc[0], false); // prevent fread / fwrite blocking
stream_set_blocking($this->ipc[1], false); // prevent fread / fwrite blocking
$ipc[0] = fopen($fileName1, "r+"); // ensures at least one writer (us) so will be non-blocking
$ipc[1] = fopen($fileName2, "r+"); // ensures at least one writer (us) so will be non-blocking
stream_set_blocking($ipc[0], false); // prevent fread / fwrite blocking
stream_set_blocking($ipc[1], false); // prevent fread / fwrite blocking
$this->ipc[0] = new FileStream($ipc[0]);
$this->ipc[1] = new FileStream($ipc[1]);
$this->getMessageSizeLimit();

$this->connected = true;
Expand Down Expand Up @@ -128,14 +132,20 @@ public function useChannelNumber($channelNumber)
public function send($message)
{
$channelNumber = $this->channelNumber;

$channelNumber = $channelNumber == 0 ? 1 : 0;

$this->checkChannelAvailability($channelNumber);

$message = $this->packMessage($message);
if (strlen($message) + 1 > $this->getMessageSizeLimit()) {
throw new \RuntimeException(sprintf("Message length exceeds max packet size of %d bytes", $this->getMessageSizeLimit()));
}

fwrite($this->ipc[$channelNumber], $message . "\0");
$this->ipc[$channelNumber]->write($message . "\0");
if ($this->ipc[$channelNumber] instanceof FlushableConnectionInterface) {
$this->ipc[$channelNumber]->flush();
}

return $this;
}
Expand All @@ -151,24 +161,16 @@ public function receive(& $success = false)
$success = false;
$channelNumber = $this->channelNumber;

$channelNumber == 0 ?
$channelNumber = 1
:
$channelNumber = 0;

$this->checkChannelAvailability($channelNumber);

$readSocket = [$this->ipc[$channelNumber]];
$writeSocket = $except = [];

if (!@stream_select($readSocket, $writeSocket, $except, 0, 10)) {
if (!$this->ipc[$channelNumber]->select(0)) {

return null;
}

$message = stream_get_line($readSocket[0], $this->getMessageSizeLimit(), "\0");
$message = $this->ipc[$channelNumber]->read("\0");

if (is_string($message) && $message !== "") {
if (is_string($message) && $message !== false) {
$message = $this->unpackMessage($message);
$success = true;
return $message;
Expand All @@ -184,30 +186,27 @@ public function receiveAll()
{
$channelNumber = $this->channelNumber;

$channelNumber == 0 ?
$channelNumber = 1
:
$channelNumber = 0;

$this->checkChannelAvailability($channelNumber);

if (!isset($this->ipc[$channelNumber])) {
throw new \RuntimeException('Channel number ' . $channelNumber . ' is already closed');
}
$readSocket = [$this->ipc[$channelNumber]];
$writeSocket = $except = [];
$messages = [];

if (@stream_select($readSocket, $writeSocket, $except, 1)) {
for (;;) {
$message = $this->receive($success);
if (!$success) {
if (!$this->ipc[$channelNumber]->select(1)) {

break;
}
return [];
}

$messages[] = $message;
$messages = [];

for (;;) {
$message = $this->receive($success);
if (!$success) {

break;
}

$messages[] = $message;
}

return $messages;
Expand All @@ -222,7 +221,7 @@ public function disconnect($channelNumber = -1)
if ($channelNumber !== -1) {
$this->checkChannelAvailability($channelNumber);

fclose($this->ipc[$channelNumber]);
$this->ipc[$channelNumber]->close();
$this->ipc[$channelNumber] = null;
$this->activeChannels[$channelNumber] = false;

Expand All @@ -233,7 +232,7 @@ public function disconnect($channelNumber = -1)
if (!$stream) {
continue;
}
fclose($stream);
$stream->close();
unlink($this->getFilename($channelNumber));
$this->ipc[$channelNumber] = null;
}
Expand Down
@@ -1,7 +1,12 @@
<?php

namespace Zeus\ServerService\Shared\Networking;
namespace Zeus\Kernel\Networking;

/**
* Interface ConnectionInterface
* @package Zeus\Kernel\Networking
* @internal
*/
interface ConnectionInterface
{
public function __construct($stream);
Expand All @@ -19,7 +24,7 @@ public function close();

public function isWritable();

public function read();
public function read($ending = false);

public function isReadable();

Expand Down

0 comments on commit 91dde6f

Please sign in to comment.