-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: prove that Fibers work if not calling Go
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Known Issues | ||
|
||
## Fibers | ||
|
||
Calling PHP functions and language constructs that themselves call [cgo](https://go.dev/blog/cgo) in [Fibers](https://www.php.net/manual/en/language.fibers.php) is known to cause crashes. | ||
|
||
This issue [is being worked on by the Go project](https://github.com/golang/go/issues/62130). | ||
|
||
|
||
In the meantime, one solution is not to use constructs (like `echo`) and functions (like `header()`) that delegate to Go from inside Fibers. | ||
|
||
This code will likely crash because it uses `echo` in the Fiber: | ||
|
||
```php | ||
$fiber = new Fiber(function() { | ||
echo 'In the Fiber'.PHP_EOL; | ||
echo 'Still inside'.PHP_EOL; | ||
}); | ||
$fiber->start(); | ||
``` | ||
|
||
Instead, return the value from the Fiber and use it outside: | ||
|
||
```php | ||
$fiber = new Fiber(function() { | ||
Fiber::suspend('In the Fiber'.PHP_EOL)); | ||
Fiber::suspend('Still inside'.PHP_EOL)); | ||
}); | ||
echo $fiber->start(); | ||
echo $fiber->resume(); | ||
$fiber->resume(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
require_once __DIR__.'/_executor.php'; | ||
|
||
return function() { | ||
$fiber = new Fiber(function() { | ||
Fiber::suspend('Fiber '.($_GET['i'] ?? '')); | ||
}); | ||
echo $fiber->start(); | ||
|
||
$fiber->resume(); | ||
}; | ||
|