本文整理汇总了PHP中uv_default_loop函数的典型用法代码示例。如果您正苦于以下问题:PHP uv_default_loop函数的具体用法?PHP uv_default_loop怎么用?PHP uv_default_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uv_default_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$system = $this;
//set up the event handler
set_error_handler(function ($severity, $message, $filePath, $line) use(&$system) {
$error = new Error($severity, $message, $filePath, $line);
$system->emit("system.error", $error);
});
//set up exception handler
set_exception_handler(function ($exception) use(&$system) {
$system->emit("system.exception", $exception);
});
//on shutdown, run the event loop
register_shutdown_function(function () {
uv_run();
});
// start the event loop
$this->eventLoop = uv_default_loop();
//set up the core module map
$modulePrefix = "\\Phastlight\\Module\\";
$this->moduleMap = array('console' => $modulePrefix . 'Console\\Main', 'process' => $modulePrefix . 'Process\\Main', 'os' => $modulePrefix . 'OS\\Main', 'http' => $modulePrefix . 'HTTP\\Main', 'timer' => $modulePrefix . 'Timer\\Main', 'util' => $modulePrefix . 'Util\\Main', 'fs' => $modulePrefix . 'FileSystem\\Main', 'net' => $modulePrefix . 'NET\\Main', 'child_process' => $modulePrefix . 'ChildProcess\\Main', 'cluster' => $modulePrefix . 'Cluster\\Main');
$this->modules = array();
}
示例2: uv_getaddrinfo
<?php
uv_getaddrinfo(uv_default_loop(), function ($s, $names) {
var_dump($names);
}, "yahoo.com", NULL, array("ai_family" => UV::AF_UNSPEC));
uv_run();
示例3: __construct
/**
* Create a new uv loop.
*
* @param LoopConfig $config
*/
public function __construct(LoopConfig $config = null)
{
parent::__construct($config);
// $this->loop = $loop ?? \uv_loop_new();
// TODO: Investigate why new uv loops cannot be deleted (segfault) and leak file descriptors...
$this->loop = \uv_default_loop();
$this->dispose = new \SplQueue();
$this->dispose->setIteratorMode(\SplQueue::IT_MODE_FIFO | \SplQueue::IT_MODE_DELETE);
$this->config->setHostResolver(new Resolver($this));
$this->config->setFilesystem(new Filesystem($this, $this->config->getFilesystemObserver()));
if (\defined('PHP_ZTS') && \PHP_ZTS) {
// TODO: Implement a pool based on uv_queue_work() if ZTS is enabled (unusable: "zend_mm_heap corrupted").
}
$this->delayCallback = function ($event) {
$watcher = $this->timerWatchers[(int) $event] ?? null;
if ($watcher) {
$this->info[Watcher::TYPE_DELAY]--;
unset($this->timerWatchers[(int) $event], $this->watchers[$watcher->id], $this->enable[$watcher->id]);
if ($watcher->referenced) {
$this->watchersReferenced--;
}
$watcher->event = null;
$this->dispose->enqueue($event);
($watcher->callback)($watcher->id, $watcher->data);
}
};
$this->repeatCallback = function ($event) {
$watcher = $this->timerWatchers[(int) $event] ?? null;
if ($watcher) {
($watcher->callback)($watcher->id, $watcher->data);
}
};
$this->streamCallback = function ($event, int $status, int $events) {
$id = (int) $event;
if (($events === 0 || $events & \UV::READABLE) && isset($this->readWatchers[$id])) {
foreach ($this->readWatchers[$id] as $watcher) {
($watcher->callback)($watcher->id, $watcher->stream, $watcher->data);
}
}
if (($events === 0 || $events & \UV::WRITABLE) && isset($this->writeWatchers[$id])) {
foreach ($this->writeWatchers[$id] as $watcher) {
($watcher->callback)($watcher->id, $watcher->stream, $watcher->data);
}
}
};
$this->signalCallback = function ($event, int $signo) {
if (isset($this->signalWatchers[$signo])) {
foreach ($this->signalWatchers[$signo] as $watcher) {
($watcher->callback)($watcher->id, $watcher->signo, $watcher->data);
}
}
};
}
示例4: uv_fs_readdir
<?php
uv_fs_readdir(uv_default_loop(), ".", 0, function ($result, $da) {
var_dump($da);
});
uv_run();
示例5: uv_default_loop
<?php
$loop = uv_default_loop();
$timer = uv_timer_init();
$i = 0;
uv_timer_start($timer, 1000, 1000, function ($stat) use(&$i, $timer, $loop) {
echo "count: {$i}" . PHP_EOL;
$i++;
if ($i > 3) {
uv_timer_stop($timer);
uv_unref($timer);
}
});
uv_run();
echo "finished";
示例6: uv_fs_utime
<?php
uv_fs_utime(uv_default_loop(), __FILE__, time(), time(), function () {
echo "Finished";
});
uv_run();
示例7: uv_fs_open
<?php
uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($r) {
uv_fs_fstat(uv_default_loop(), $r, function ($result, $da) {
var_dump($da);
});
});
uv_run();
示例8: uv_fs_chmod
<?php
uv_fs_chmod(uv_default_loop(), "moe", 0777, function ($result) {
var_dump($result);
});
uv_run();
示例9: uv_pipe_init
<?php
$in = uv_pipe_init(uv_default_loop(), true);
echo "HELLO ";
$stdio = array();
$stdio[] = uv_stdio_new($in, UV::CREATE_PIPE | UV::READABLE_PIPE);
$fp = fopen("php://stdout", "w");
$stdio[] = uv_stdio_new($fp, UV::INHERIT_FD | UV::WRITABLE_PIPE);
$flags = 0;
uv_spawn(uv_default_loop(), "php", array('-r', 'var_dump($_ENV);'), $stdio, "/usr/bin/", array("key" => "hello"), function ($process, $stat, $signal) {
uv_close($process, function () {
});
}, $flags);
uv_run();
示例10: uv_fs_event_init
<?php
uv_fs_event_init(uv_default_loop(), "/tmp/", function ($rsc, $name, $event, $stat) {
var_dump($name);
var_dump($event);
}, 0);
uv_run();
示例11: uv_fs_open
<?php
uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($read_fd) {
$stdout = 0;
uv_fs_sendfile(uv_default_loop(), $stdout, $read_fd, 0, 6, function ($result) {
});
});
uv_run();
示例12: uv_fs_readlink
<?php
uv_fs_readlink(uv_default_loop(), "li", function ($result, $buffer) {
var_dump($result);
var_dump($buffer);
});
uv_run();
示例13: uv_fs_open
<?php
uv_fs_open(uv_default_loop(), "/dev/tty", UV::O_RDONLY, 0, function ($r) {
$tty = uv_tty_init(uv_default_loop(), $r, 1);
var_dump(uv_tty_get_winsize($tty, $width, $height));
var_dump($width, $height);
});
uv_run();
示例14: __construct
public function __construct()
{
$this->eventBase = uv_default_loop();
}
示例15: uv_fs_unlink
<?php
uv_fs_unlink(uv_default_loop(), "moe", function ($result) {
var_dump($result);
});
uv_run();