php / php/doc-en

Clarify when fibers can be switched

Open
#2,390 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Category: Fibers enhancement
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Description

Since version 8.2.0 when trying to create fiber in a function passed to pcntl_signal an "Cannot switch fibers in current execution context" error occurs.
The documentation says only about limitation in the destructor.

The following code:

<?php

pcntl_signal(SIGINT, function () {
	$fiber = new Fiber(function () {
		Fiber::suspend('test');
	});

	var_dump($fiber->start());
});

posix_kill(getmypid(), SIGINT);
pcntl_signal_dispatch();

Resulted in this output:

string(4) "test"

But I expected this output instead:

Uncaught FiberError: Cannot switch fibers in current execution context
PHP Version

PHP 8.2.0

Operating System

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the PHP Fiber documentation's restrictions on switching and compare them with the provided PHP 8.2 pcntl_signal example. Update the documentation to explain when fibers can be switched, including signal-handler behavior, and verify that the example's actual behavior is accurately described.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.