Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Swoole\Client; use Swoole\Database\MySQLi; use Swoole\Database\MySQLiRecor..
Decoded Output download
<?php
namespace Swoole\Client;
use Swoole\Database\MySQLi;
use Swoole\Database\MySQLiRecord;
/**
* MySQL
* concurrent mysql client
* Class CoMySQL
* @package Swoole\Client
*/
class CoMySQL
{
protected $config;
protected $list;
protected $results;
protected $sqlIndex = 0;
protected $pool = array();
function __construct($db_key = 'master')
{
$this->config = \Swoole::getInstance()->config['db'][$db_key];
//
$this->config['persistent'] = false;
}
protected function getConnection()
{
//
if (count($this->pool) == 0)
{
$db = new MySQLi($this->config);
$db->connect();
return $db;
}
//
else
{
return array_pop($this->pool);
}
}
/**
* @param $sql
* @param null $callback
* @return bool|CoMySQLResult
*/
function query($sql, $callback = null)
{
$db = $this->getConnection();
$result = $db->queryAsync($sql);
if (!$result)
{
return false;
}
$retObj = new CoMySQLResult($db, $callback);
$retObj->sql = $sql;
$this->list[] = $retObj;
$retObj->id = $this->sqlIndex++;
$db->_co_id = $retObj->id;
return $retObj;
}
function wait($timeout = 1.0)
{
$_timeout_sec = intval($timeout);
$_timeout_usec = intval(($timeout - $_timeout_sec) * 1000 * 1000);
$taskSet = $this->list;
$processed = 0;
do
{
$links = $errors = $reject = array();
foreach ($taskSet as $k => $retObj)
{
$links[] = $errors[] = $reject[] = $retObj->db;
}
//wait mysql server response
if (!mysqli_poll($links, $errors, $reject, $_timeout_sec, $_timeout_usec))
{
continue;
}
/**
* @var $link mysqli
*/
foreach ($links as $link)
{
$_retObj = $this->list[$link->_co_id];
$result = $link->reap_async_query();
if ($result)
{
if (is_object($result))
{
$_retObj->result = new MySQLiRecord($result);
if ($_retObj->callback)
{
call_user_func($_retObj->callback, $_retObj->result);
}
$_retObj->code = 0;
}
else
{
$_retObj->code = CoMySQLResult::ERR_NO_OBJECT;
}
}
else
{
trigger_error(sprintf("MySQLi Error: %s", $link->error));
$_retObj->code = $link->errno;
}
//
unset($taskSet[$link->_co_id]);
$processed++;
}
} while ($processed < count($this->list));
//
foreach ($this->list as $_retObj)
{
$this->pool[] = $_retObj->db;
}
//
$this->list = array();
$this->sqlIndex = 0;
return $processed;
}
}
class CoMySQLResult
{
public $id;
public $db;
public $callback = null;
/**
* @var MySQLiRecord
*/
public $result;
public $sql;
public $code = self::ERR_NO_READY;
const ERR_NO_READY = 6001;
const ERR_TIMEOUT = 6002;
const ERR_NO_OBJECT = 6003;
function __construct(\mysqli $db, callable $callback = null)
{
$this->db = $db;
$this->callback = $callback;
}
} ?>
Did this file decode correctly?
Original Code
<?php
namespace Swoole\Client;
use Swoole\Database\MySQLi;
use Swoole\Database\MySQLiRecord;
/**
* MySQL
* concurrent mysql client
* Class CoMySQL
* @package Swoole\Client
*/
class CoMySQL
{
protected $config;
protected $list;
protected $results;
protected $sqlIndex = 0;
protected $pool = array();
function __construct($db_key = 'master')
{
$this->config = \Swoole::getInstance()->config['db'][$db_key];
//
$this->config['persistent'] = false;
}
protected function getConnection()
{
//
if (count($this->pool) == 0)
{
$db = new MySQLi($this->config);
$db->connect();
return $db;
}
//
else
{
return array_pop($this->pool);
}
}
/**
* @param $sql
* @param null $callback
* @return bool|CoMySQLResult
*/
function query($sql, $callback = null)
{
$db = $this->getConnection();
$result = $db->queryAsync($sql);
if (!$result)
{
return false;
}
$retObj = new CoMySQLResult($db, $callback);
$retObj->sql = $sql;
$this->list[] = $retObj;
$retObj->id = $this->sqlIndex++;
$db->_co_id = $retObj->id;
return $retObj;
}
function wait($timeout = 1.0)
{
$_timeout_sec = intval($timeout);
$_timeout_usec = intval(($timeout - $_timeout_sec) * 1000 * 1000);
$taskSet = $this->list;
$processed = 0;
do
{
$links = $errors = $reject = array();
foreach ($taskSet as $k => $retObj)
{
$links[] = $errors[] = $reject[] = $retObj->db;
}
//wait mysql server response
if (!mysqli_poll($links, $errors, $reject, $_timeout_sec, $_timeout_usec))
{
continue;
}
/**
* @var $link mysqli
*/
foreach ($links as $link)
{
$_retObj = $this->list[$link->_co_id];
$result = $link->reap_async_query();
if ($result)
{
if (is_object($result))
{
$_retObj->result = new MySQLiRecord($result);
if ($_retObj->callback)
{
call_user_func($_retObj->callback, $_retObj->result);
}
$_retObj->code = 0;
}
else
{
$_retObj->code = CoMySQLResult::ERR_NO_OBJECT;
}
}
else
{
trigger_error(sprintf("MySQLi Error: %s", $link->error));
$_retObj->code = $link->errno;
}
//
unset($taskSet[$link->_co_id]);
$processed++;
}
} while ($processed < count($this->list));
//
foreach ($this->list as $_retObj)
{
$this->pool[] = $_retObj->db;
}
//
$this->list = array();
$this->sqlIndex = 0;
return $processed;
}
}
class CoMySQLResult
{
public $id;
public $db;
public $callback = null;
/**
* @var MySQLiRecord
*/
public $result;
public $sql;
public $code = self::ERR_NO_READY;
const ERR_NO_READY = 6001;
const ERR_TIMEOUT = 6002;
const ERR_NO_OBJECT = 6003;
function __construct(\mysqli $db, callable $callback = null)
{
$this->db = $db;
$this->callback = $callback;
}
}
Function Calls
None |
Stats
MD5 | c6ccbbe8f8777a7ed9a3aaa8a06cf2c1 |
Eval Count | 0 |
Decode Time | 108 ms |