繁体   English   中英

amphp 库适用于 xampp 但不适用于我的网络主机

[英]amphp libary works on xampp but not on my webhoster

我想并行执行数组中的域。 它可以工作,但只能通过 xampp 而不是在我的网络主机上。 为什么?

我用这个:

https://github.com/amphp/parallel

代码:

<?php

require __DIR__ . '/../vendor/autoload.php';

use Amp\Parallel\Worker;
use Amp\Promise;

$urls = [
    'https://secure.php.net',
    'https://amphp.org',
    'https://github.com',
];

$promises = [];
foreach ($urls as $url) {
    $promises[$url] = Worker\enqueueCallable('file_get_contents', $url);
}

$responses = Promise\wait(Promise\all($promises));

foreach ($responses as $url => $response) {
    \printf("Read %d bytes from %s\n", \strlen($response), $url);
}

?>

错误代码如果我在我的网络主机上运行它:

在供应商/amphp/parallel/lib/Worker/DefaultPool.php 上,池中的工作人员以代码 -1 第 250 行意外退出池中的工作人员在代码 -1 第 250 行上意外退出

致命错误:未捕获的 Amp\\Process\\ProcessException:无法在 /kunden/559288_442/webseiten/webhoster/parallel/vendor/amphp/process/lib/Internal/Posix/Runner.php:142 中列出打开的文件描述符:#0 /kunden/559288_442/webseiten/webhoster/parallel/vendor/amphp/process/lib/Internal/Posix/Runner.php(88): Amp\\Process\\Internal\\Posix\\Runner->generateFds() #1 /kunden/559288_442 /webseiten/webhoster/parallel/vendor/amphp/process/lib/Process.php(108): Amp\\Process\\Internal\\Posix\\Runner->start('{ ('/usr/bin/ph...', '', Array, Array) #2 [内部函数]: Amp\\Process\\Process->Amp\\Process{closure}() #3 /kunden/559288_442/webseiten/webhoster/parallel/vendor/amphp/amp/lib/ Coroutine.php(67): Generator->current() #4 /kunden/559288_442/webseiten/webhoster/parallel/vendor/amphp/amp/lib/functions.php(96): Amp\\Coroutine->__construct(Object( Generator)) #5 /kunden/559288_442/webseiten/webhoster/parallel/vendor/amphp/process/lib/Process.php(110): Amp\\call(Object(Closure)) #6 /kunden/4 in /kunden/ 559288_442/webseiten/webhoster/parallel/vendor/amphp/parallel/lib/Context/Process.php 在线 202

根据提供的信息,您在 Web 主机服务器上的用户没有读取 Amp 为查找文件描述符而读取的路径所需的权限。 一种疏忽。

据我所知(通过阅读 Amp 源代码)当您的网络主机不支持线程时,创建进程是最后的手段,这将成为所有共享主机提供商的标准。

使用reactphp/filesystem异步读取文件。 过去我已经能够在共享主机上成功使用它,即使它也创建了子进程。 幸运的是,它创建它们的方式不需要访问通常在共享主机环境中受到保护的目录。

<?php

require dirname(__DIR__) . '/vendor/autoload.php';

// With Amp loop;
// $loop = new Amp\ReactAdapter\ReactAdapter((new Amp\Loop\DriverFactory)->create());

// With React EventLoop;
$loop = \React\EventLoop\Factory::create();

$filesystem = \React\Filesystem\Filesystem::create($loop);

// This returns a react/promise, which can be yielded in amp coroutines
$filesystem->file(__FILE__)->getContents()->then(function ($contents) {
    echo $contents, PHP_EOL;
}, function ($e) {
    echo $e->getMessage(), PHP_EOL;
});

// You only need this if you are running outside of an Amp Loop.
$loop->run();

您可以将 reactphp/filesystem 与amphp/react-adapter 配对以在库之间共享单个循环。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM