Skip to content

Commit

Permalink
config: introduce 'daemon_host" and 'daemon_port' parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill committed Jun 27, 2018
1 parent 910cfdf commit db05952
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 55 deletions.
12 changes: 6 additions & 6 deletions protected/components/Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/
class Daemon extends CApplicationComponent
{
public $host; // Service host.
public $servicePort; // Service port.
public $errorMsg; // Error message.
public $host; // Service host.
public $port; // Service port.
public $errorMsg; // Error message.

const DAEMON_CHECK_OK = 0; // Daemon check OK.
const DAEMON_CHECK_INACTIVE = 1; // Daemon seems to be inactive or not responding.
Expand Down Expand Up @@ -304,12 +304,12 @@ private function sendRequest($request, &$responce)
}

// Connect socket
$result = @socket_connect($sock, '127.0.0.1', '50');
$result = @socket_connect($sock, $this->host, $this->port);
if( FALSE === $result )
{
$responce = "Error connecting to daemon.";
$responce = "Error connecting to daemon ".$this->host.":".$this->port;
return -1;
}
}

// Read greeting message from daemon
$responce = socket_read($sock, 128);
Expand Down
13 changes: 13 additions & 0 deletions protected/config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ function getCommonParams()

}

/**
*
*/
function daemonParams()
{
$userParams = parse_ini_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'user_params.ini');

return array(
'class'=>'Daemon',
'host'=>$userParams['daemon_host'],
'port'=>$userParams['daemon_port'],
);
}

/**
* This helper function is used for extracting db connection parameters from INI
Expand Down
6 changes: 1 addition & 5 deletions protected/config/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
'db'=>dbParams(),
'dbTest'=>dbParams('test_'),

'daemon'=>array(
'class'=>'Daemon',
'host'=>'127.0.0.1',
'servicePort'=>'50',
),
'daemon'=> daemonParams(),

'log'=>array(
'class'=>'CLogRouter',
Expand Down
6 changes: 1 addition & 5 deletions protected/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@
'connectionID' => 'db',
'sessionTableName' => '{{YiiSession}}'
),
'daemon' => array(
'class' => 'Daemon',
'host' => '127.0.0.1',
'servicePort' => '50',
),
'daemon' => daemonParams(),
'errorHandler' => array(
// use 'site/error' action to display errors
'errorAction' => 'site/error',
Expand Down
37 changes: 0 additions & 37 deletions protected/config/user_params.ini

This file was deleted.

3 changes: 1 addition & 2 deletions protected/config/user_params.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ db_password=crashfixpwd
; so on.
db_table_prefix=tbl_



daemon_port=50

0 comments on commit db05952

Please sign in to comment.