Skip to content

Commit

Permalink
Update to v 1.3 (add logger and some more
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav WEB committed Jun 25, 2014
1 parent 43020fc commit a274e0d
Showing 11 changed files with 406 additions and 182 deletions.
16 changes: 16 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
namespace WebSockets; // declare namespace for the current module "WebSockets"

use Zend\ModuleManager\Feature\AutoloaderProviderInterface, // provide autoloader configurations
Zend\ModuleManager\Feature\ViewHelperProviderInterface, // provide view helpers
Zend\ModuleManager\Feature\ConfigProviderInterface, // interfaces for configurator
Zend\ModuleManager\Feature\ConsoleUsageProviderInterface, // interfaces for CLI
Zend\ModuleManager\Feature\ConsoleBannerProviderInterface, // provide console banner
@@ -20,6 +21,7 @@
*/
class Module implements
AutoloaderProviderInterface,
ViewHelperProviderInterface,
ConfigProviderInterface,
ConsoleUsageProviderInterface,
ConsoleBannerProviderInterface {
@@ -56,6 +58,20 @@ public function getAutoloaderConfig()
];
}

/**
* getViewHelperConfig() Setup your view helpers
* @access public
* @return array
*/
public function getViewHelperConfig()
{
return [
'invokables' => [
'socket' => '\WebSockets\View\Helper\Socket',
],
];
}

/**
* getServiceConfig() method of loading services
* @access public
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ZF2 PHP WebSocket Server v1.1.2
ZF2 PHP WebSocket Server v1.3
![Alt text](https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRpi209uZxeUrXP6cFLxuFbsTQkm9V0anTgp7Y-ltpEG6sw-txlvg "WebSockets")
--------------------------------------

@@ -9,6 +9,20 @@ ZF2 PHP WebSocket Server v1.1.2

#### Changes
------------
v1.3
- Add logger

v1.2
- Add verbose turner (console show\hide) (@see module.config.php)
- Add socket function's exception handler
- Fixed CLI stdout>> encoding
- Add ViewHelper for a simple get server config params into view
```
<?php
// for example
echo $this->socket()->config('host'); // print 127.0.0.1 ?>
?>
v1.1.2
- Console stdout>> while starting server
@@ -35,9 +49,9 @@ You're always can ask me for this module if you have write me [issue](https://gi
2. Change host address in module.config.php
3. Go to your shell command-line interface and type: `php -q index.php websocket open`
3. Go to your shell command-line interface and type (running server as background): `php -q index.php websocket open`
4. Setup your Client-side script's to communicating with the server .. ws://host:port/websockets/open communicating as similarity
4. Setup your Client-side script's to communicating with the server .. ws://host:port/websocket/open communicating as similarity
--------------------------------------
In order to start using the module clone the repo in your vendor directory or add it as a submodule if you're already using git for your project:
@@ -50,4 +64,10 @@ In order to start using the module clone the repo in your vendor directory or ad
The module will also be available as a Composer package soon.
#### Libraries used
------------
- [Zend Framework 2.3](https://github.com/zendframework/zf2)
![Alt text](http://cs620519.vk.me/v620519508/a755/4lwSwtVe59g.jpg "WebSockets")
12 changes: 6 additions & 6 deletions autoload_classmap.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
// Generated by ZF2's ./bin/classmap_generator.php
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);

return array(
'WebSockets\Module' => __DIR__ .DS.'Module.php',
'WebSockets\Controller\WebsocketCLIController' => __DIR__ .DS.'src'.DS.'WebSockets'.DS.'Controller'.DS.'WebsocketCLIController.php',
'WebSockets\Controller\WebsocketController' => __DIR__ .DS.'src'.DS.'WebSockets'.DS.'Controller'.DS.'WebsocketController.php',
'WebSockets\Exception\ExceptionStrategy' => __DIR__ .DS.'src'.DS.'WebSockets'.DS.'Exception'.DS.'ExceptionStrategy.php',
'WebSockets\Service\WebsocketServer' => __DIR__ .DS.'src'.DS.'WebSockets'.DS.'Service'.DS.'WebsocketServer.php',
'WebSockets\Module' => __DIR__ .'Module.php',
'WebSockets\Controller\WebsocketCLIController' => __DIR__ .'/src/WebSockets/Controller/WebsocketCLIController.php',
'WebSockets\Controller\WebsocketController' => __DIR__ .'/src/WebSockets/Controller/WebsocketController.php',
'WebSockets\Exception\ExceptionStrategy' => __DIR__ .'/src/WebSockets/Exception/ExceptionStrategy.php',
'WebSockets\Service\WebsocketServer' => __DIR__ .'/src/WebSockets/Service/WebsocketServer.php',
'WebSockets\View\Helper\Socket' => __DIR__ .'/src/WebSockets/View/Helper/Socket.php',
);
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "stanislav-web/ZF2-PHP-WebSocket-Server",
"description": "ZendFramework2 PHP WebSocket Server v1.1.2",
"description": "ZendFramework2 PHP WebSocket Server v1.3",
"type": "library",
"keywords": [
"zf2",
"websockets",
"websocket server"
"websocket server",
"websockets php",
"websocket php server"
],
"homepage": "https://github.com/stanislav-web/ZF2-PHP-WebSocket-Server",
"authors": [
11 changes: 9 additions & 2 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -11,8 +11,15 @@

'websockets' => [
'server' => [ // setup WebSocket connection
'host' => '127.0.0.1',
'port' => 9000
'host' => '127.0.0.1',
'port' => 9000,
'clients_limit' => 10, // limit active connections per socket loop
'max_disconnections_time' => 30, // limit active connections per socket loop
'verbose' => true, // console stdout>>
'encoding' => 'UTF-8', // console encoding
'log' => true,
'logfile' => 'logs/socket/actions.log',
'action' => '/websocket/open' // open controller/action from websocket.Controller
],
],

8 changes: 4 additions & 4 deletions config/service.config.php
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
* Configurator services module callable using ServiceManager
*/

return array(
return [

'invokables' => array(
'invokables' => [
'websocket.Server' => 'Websocket\Service\WebsocketServer', // Service for a permanent connection with
),
);
],
];
5 changes: 3 additions & 2 deletions src/WebSockets/Controller/WebsocketCLIController.php
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ public function openAction()

try {
if($this->_server == null) $this->_server = new Server($config['server']);
$this->_server->start();
// running server
$this->_server->run();
}
catch(Exception\ExceptionStrategy $e)
{
@@ -81,7 +82,7 @@ public function systemAction()
}
catch(Exception\ExceptionStrategy $e)
{
echo $e->getMessage();
echo $e->throwMessage();
}
}

11 changes: 6 additions & 5 deletions src/WebSockets/Controller/WebsocketController.php
Original file line number Diff line number Diff line change
@@ -38,13 +38,14 @@ public function openAction()

// Try to start server

try {
try {
if($this->_server == null) $this->_server = new Server($config['server']);
$this->_server->start();
}
catch (Exception\ExceptionStrategy $e)
// running server
$this->_server->run();
}
catch(Exception\ExceptionStrategy $e)
{
echo $e->getMessage();
}
}
}
}
26 changes: 21 additions & 5 deletions src/WebSockets/Exception/ExceptionStrategy.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace WebSockets\Exception;

/**
* Exception used when a file read or write fails
* ExceptionStrategy for WebSocket module
* @package Zend Framework 2
* @subpackage WebSockets
* @since PHP >=5.4
@@ -13,10 +12,27 @@
* @license Zend Framework GUI licene
* @filesource /module/Websocket/src/Websocket/Exception/ExceptionStrategy.php
*/
class ExceptionStrategy extends \RuntimeException {
class ExceptionStrategy extends \UnexpectedValueException{

/**
* $_message only message in console
* @var type string
* @access protected
*/
protected $_message = null;


/**
* $_line only message in console
* @var type string
* @access protected
*/
protected $_line = null;



public function getMessage()
public function throwMessage()
{
return parent::getMessage("#".$this->getCode()."\r\n ".$this->getFile()." ".$this->getLine()."\r\n".$this->getMessage());
return $this->getMessage().' [line: '.$this->getLine().']';
}
}
Loading

0 comments on commit a274e0d

Please sign in to comment.