“农民世界”链游系统开发应用场景讲解丨FarmersWorld(农民世界)DAPP游戏系统开发场景代码讲解如下:
/**
* Save pid.
*
* @throws Exception
*/
“农民世界”链游接口:
protected static function saveMasterPid()
{
if (static::$_OS !== OS_TYPE_LINUX) {
return;
}
static::$_masterPid = posix_getpid();
if (false === file_put_contents(static::$pidFile, static::$_masterPid)) {
throw new Exception('can not save pid to ' . static::$pidFile);
}
}
“农民世界”数据获取方式:
protected static function getEventLoopName()
{
if (static::$eventLoopClass) {
return static::$eventLoopClass;
}
if (!class_exists('\Swoole\Event')) {
unset(static::$_availableEventLoops['swoole']);
}
$loop_name = '';
foreach (static::$_availableEventLoops as $name=>$class) {
if (extension_loaded($name)) {
$loop_name = $name;
break;
}
}
if ($loop_name) {
if (interface_exists('\React\EventLoop\LoopInterface')) {
switch ($loop_name) {
case 'libevent':
static::$eventLoopClass = '\Workerman\Events\React\ExtLibEventLoop';
break;
case 'event':
static::$eventLoopClass = '\Workerman\Events\React\ExtEventLoop';
break;
default :
static::$eventLoopClass = '\Workerman\Events\React\StreamSelectLoop';
break;
}
} else {
static::$eventLoopClass = static::$_availableEventLoops[$loop_name];
}
} else {
static::$eventLoopClass = interface_exists('\React\EventLoop\LoopInterface')? '\Workerman\Events\React\StreamSelectLoop':'\Workerman\Events\Select';
}
return static::$eventLoopClass;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70019421/viewspace-2906954/ ,如需转载,请注明出处,否则将追究法律责任。