Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sergey Zhuk:
Understanding ReactPHP Event Loop Ticks
Sep 29, 2017 @ 14:46:14

Sergey Zhuk has a new post to his site that hopes to help you better understand "ticks" in ReactPHP. Ticks are a feature of the tool that are used to track when a process or queue has been executed.

Tick is one loop iteration where every callback in the queues has been executed synchronously and in order. ReactPHP event loop implementation has two main methods to work with ticks: nextTick [and] futureTick.

Both methods can be used to schedule a callback to be invoked on a future iteration of the event loop. When being executed a callback receives an instance of the event loop as an argument. But then what’s the difference between next and future ticks? Let’s figure this out.

He then starts in talking about the difference between "future" and "next" ticks, illustrating with a simple "stream select" loop. He then shows how to work with the tick queue for both the future and next ticks and what the result is of each function call inside them. He includes the output of his sample scripts and what happens if a few things change.

Consider a tick as one loop iteration where every callback in the queues has been executed synchronously and in order. That means that a tick could be long, it could be short, but we want it to be as short as possible. So, don’t place long-running tasks in callbacks, because they will block the loop. When a tick a being stretched out, the event loop won’t be able to check the events, which means losing performance for your asynchronous code.
tagged: reactphp tutorial tick iteration next future example

Link: http://seregazhuk.github.io/2017/09/25/reactphp-event-loop-ticks/

PHP 10.0 Blog:
We are doomed! (and Ticks in PHP)
Jun 20, 2007 @ 15:29:00

In this new post to the PHP 10.0 blog, Stas mentions the "impending doom" of PHP that's been going around the community, including in this post on the TechRepublic site.

He does, however, branch off into something much more interesting that seems to be somewhat ignored by developers - the use of ticks on their code:

This is something named "ticks" - I wonder how many of the PHP developers heard about it and of those how many actually used it. Could it be used for offloading long-running I/O-bound tasks or grouping them together (e.g. so we could wait for DB and HTTP in parallel and not sequentially)? Would there be any use at all for such functionality and if so - how it's supposed to work? I.e. how would you know it's done and how you would collect and use the results?

It's suggested in the comments that it could be used for any kind of application that might need the pseudo-multithreading it offers (including something like scripts needing multiple TCP connections).

tagged: doom tick multithread declare construct doom tick multithread declare construct

Link:

PHP 10.0 Blog:
We are doomed! (and Ticks in PHP)
Jun 20, 2007 @ 15:29:00

In this new post to the PHP 10.0 blog, Stas mentions the "impending doom" of PHP that's been going around the community, including in this post on the TechRepublic site.

He does, however, branch off into something much more interesting that seems to be somewhat ignored by developers - the use of ticks on their code:

This is something named "ticks" - I wonder how many of the PHP developers heard about it and of those how many actually used it. Could it be used for offloading long-running I/O-bound tasks or grouping them together (e.g. so we could wait for DB and HTTP in parallel and not sequentially)? Would there be any use at all for such functionality and if so - how it's supposed to work? I.e. how would you know it's done and how you would collect and use the results?

It's suggested in the comments that it could be used for any kind of application that might need the pseudo-multithreading it offers (including something like scripts needing multiple TCP connections).

tagged: doom tick multithread declare construct doom tick multithread declare construct

Link:


Trending Topics: