Skip to content

Tick function is not working correctly inside fibers #8960

Description

@Alimadadi

Description

The following code:

<?php

declare(ticks=1);

register_tick_function(function(){
  if(Fiber::getCurrent() !== null) {
    Fiber::suspend();
  }
});


for($i = 3; $i--;)
{
  $fibers[$i] = new fiber(function (){
    echo "1\n";
    echo "2\n";
    echo "3\n";
  });

  $fibers[$i]->start();
}

Resulted in this output:

1
1
2
3
1
2
3

But I expected this output instead:

1
1
1

Explanation:
If we are inside a fiber, after each tick, the tick function should call Fiber::suspend().
But currently this tick function only works inside first Fiber.

PHP Version

PHP 8.1.8

Operating System

macOS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions