seregazhuk / reactphp-blog-series Goto Github PK
View Code? Open in Web Editor NEWExamples for posts from ReactPHP series
Examples for posts from ReactPHP series
So I have modified the example you have given on your site. I noticed that whatever value you have the timeout set for, no matter how many items you feed into the array, the scripts execution time will be as long as the timeout is set for plus whatever you have running before or after it. I believe this is because the timer being used is simply to prevent long running scripts that timeout. Nevertheless, if I have 1000 items in the queue and a timeout of 2 seconds, everything fails. 2 seconds is like a hard limit for the execution time of the script. If I put in 1 URL to a file, like a 1kb thumbnail and put the timeout at 30, the execution time will be just over 30 seconds. I believe the function below is where the problem needs addressing. Either the timer needs to be canceled or the promise needs to be rejected or accepted? I am not sure what is the best practice as I am still new to reactPHP.
Keep up the great work, your site by far is the best on the web and your videos are top notch!
`
public function parse(array $urls = [], $timeout = 10, $concurrencyLimit = 8)
{
$queue = $this->initQueue($concurrencyLimit);
foreach ($urls as $url) {
$promise = $queue($url)->then(
function (\Psr\Http\Message\ResponseInterface $response) {
if ($response->getStatusCode() == 200) {
$this->parsed[] = $response->getStatusCode();
// TODO Cancel timer or fulfill / reject promise???
}
},
function (Exception $exception) use ($url) {
$this->errors[$url] = $exception->getMessage();
}
);
$this->loop->addTimer($timeout, function () use ($promise) {
$promise->cancel();
});
}
}
`
Warning: require(C:\xampp\htdocs\video\video_streaming\reactphp_blog_series_master\ticks/../../vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\video\video_streaming\reactphp_blog_series_master\ticks\all.php on line 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.