Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are php ticks non-blocking

I randomly came across things like:

<?php
    declare(ticks=1);

    // using a function as the callback
    register_tick_function('my_function', true);

    // using an object->method
    $object = new my_class();
    register_tick_function(array(&$object, 'my_method'), true);
?>

Which can be found at register_tick_function.

I wanted to know if using this in php was blocking or not?

EDIT: What I mean by this if I have more then one php tick running started on the same thread is it able to handle IO in the background while the other ticks run or does it need to wait for each tick to give over control?

like image 430
WojonsTech Avatar asked Mar 23 '13 10:03

WojonsTech


People also ask

What are ticks in PHP?

Put simply, a tick is a special event that occurs internally in PHP each time it has executed a certain number of statements. These statements are internal to PHP and loosely correspond to the statements in your script.

What is tick function?

The tick function is unlike other lifecycle functions in that you can call it any time, not just when the component first initialises. It returns a promise that resolves as soon as any pending state changes have been applied to the DOM (or immediately, if there are no pending state changes).


1 Answers

Tick functions are blocking. PHP in general does not (natively) support parallel execution in the same request. So no, you will not be able to handle IO in the background, or something like that.

What ticks does is more or less inserting calls to the tick function after every statement. So what you get is something like this:

tick();
$a = 1;
tick();
$b = 2;
tick();
// ...

And it will behave just like that :)

Though, just so you understand whether or not this is actually significant: When a callback is executed in JS (e.g. a timeout / event is fired), then it's just as blocking.

like image 195
NikiC Avatar answered Oct 10 '22 21:10

NikiC