PATH:
opt
/
alt
/
tests
/
alt-php72-pecl-pthreads-zts_3.2.0-1.el8
/
tests
--TEST-- Test sane handling of resources from foreign contexts --DESCRIPTION-- Test that resources from other thread contexts can properly be accessed and are only destroyed by their owner --FILE-- <?php class myWorker extends Worker { private $foreignResource; public function __construct($useResource) { $this->foreignResource = $useResource; var_dump([ 'Resource received and stored:', is_resource($useResource), is_resource($this->foreignResource), ]); } public function run () { // polute EG(regular_list) with another resource of our own $localThreadFP = tmpfile(); var_dump(array( 'Foreign resource conversion test:', // test conversion followed by destruction // the resource shall be added and removed from // PTHREADS_ZG(resources) and EG(regular_list) by the following // statement: is_resource($this->foreignResource), // now make the resource permanently available locally to tasks by // storing it in a variable. It will stay in PTHREADS_ZG(resources) // and EG(regular_list) until the worker is shutdown): is_resource($foreignResource = $this->foreignResource), // test that we still get the correct resource when it's already in // EG(regular_list) $foreignResource === $this->foreignResource )); fclose($localThreadFP); } } class Work extends Threaded { public function run () { $foreignResource = $this->worker->foreignResource; var_dump(array( 'Foreign resource is accessible from task:', is_resource($foreignResource), $foreignResource === $this->worker->foreignResource, 'wrote ' . fwrite($foreignResource, '42') . ' bytes', )); } } $fp = tmpfile(); $task = new Work(); $worker = new myWorker($fp); $worker->start(); $worker->stack($task); var_dump(array( 'Our worker is shutdown:', $worker->shutdown(), )); var_dump(array( 'Our resource is still valid:', is_resource($fp) && rewind($fp), fread($fp, 2) === "42", )); var_dump(array( 'Our resource can be closed:', fclose($fp), )); var_dump(array( 'Our resource is closed:', !is_resource($fp), )); ?> --EXPECT-- array(3) { [0]=> string(29) "Resource received and stored:" [1]=> bool(true) [2]=> bool(true) } array(4) { [0]=> string(33) "Foreign resource conversion test:" [1]=> bool(true) [2]=> bool(true) [3]=> bool(true) } array(4) { [0]=> string(41) "Foreign resource is accessible from task:" [1]=> bool(true) [2]=> bool(true) [3]=> string(13) "wrote 2 bytes" } array(2) { [0]=> string(23) "Our worker is shutdown:" [1]=> bool(true) } array(3) { [0]=> string(28) "Our resource is still valid:" [1]=> bool(true) [2]=> bool(true) } array(2) { [0]=> string(27) "Our resource can be closed:" [1]=> bool(true) } array(2) { [0]=> string(23) "Our resource is closed:" [1]=> bool(true) }
[+]
..
[-] magic-methods-isset-unset.phpt
[edit]
[-] traits-scope.inc
[edit]
[-] interface.phpt
[edit]
[-] oomethods.phpt
[edit]
[-] class-static-properties-order-dependencies.phpt
[edit]
[-] interfaces.phpt
[edit]
[-] lexical-vars.phpt
[edit]
[-] thorn-in-side.phpt
[edit]
[-] workers-no-collect.phpt
[edit]
[-] class-static-properties-2.phpt
[edit]
[-] workers-constant-copy.phpt
[edit]
[-] socket-getsockname-af-inet.phpt
[edit]
[-] resource-keeping.phpt
[edit]
[-] normalize-members.phpt
[edit]
[-] workers-no-join.phpt
[edit]
[-] socket-connect-error-unix.phpt
[edit]
[-] complex-statics-set-null.phpt
[edit]
[-] included-files.phpt
[edit]
[-] magic-methods-get-set.phpt
[edit]
[-] pthreads-inherit-none-class-constant.phpt
[edit]
[-] pools-default.phpt
[edit]
[-] immutable-threaded-members.phpt
[edit]
[-] closure-secondary-thread-copy.phpt
[edit]
[-] unset-defaults.phpt
[edit]
[-] nested-non-threaded-object-references.phpt
[edit]
[-] iterator-no-refs.phpt
[edit]
[-] socket-setoption.phpt
[edit]
[-] shutdown-handler.phpt
[edit]
[-] wait.phpt
[edit]
[-] socket-getsockname-af-unix.phpt
[edit]
[-] corrupted-resources.phpt
[edit]
[-] constant-ast-copy-missing-type.phpt
[edit]
[-] hacking-serials.phpt
[edit]
[-] null-member-crash.phpt
[edit]
[-] runtime-inheritance.phpt
[edit]
[-] socket-sentto-recvfrom-ipv6-udp.phpt
[edit]
[-] trait-aliases-reflection.phpt
[edit]
[-] ipv6_skipif.inc
[edit]
[-] trait-alias-bug.phpt
[edit]
[-] statics.phpt
[edit]
[-] workers-no-shutdown-before-start.phpt
[edit]
[-] synchronization.phpt
[edit]
[-] anon-unbound-double-inherited.phpt
[edit]
[-] static-scope-vars.phpt
[edit]
[-] selective-inheritance.phpt
[edit]
[-] constants.phpt
[edit]
[-] chunk.phpt
[edit]
[-] workers-no-start.phpt
[edit]
[-] closures-as-members-repeated-reallocation.phpt
[edit]
[-] new-class-after-thread-creation.phpt
[edit]
[-] socket-ipv6loop.phpt
[edit]
[-] includeme.inc
[edit]
[-] norefs.phpt
[edit]
[-] object-comparison.phpt
[edit]
[-] unprepared-entry-static-segfault.phpt
[edit]
[-] constant-array.phpt
[edit]
[-] socket-connect-error-win32.phpt
[edit]
[-] socket-select-unix.phpt
[edit]
[-] verify-overload.phpt
[edit]
[-] object-cast.phpt
[edit]
[-] foreign-private-members.phpt
[edit]
[-] statics-thorn-in-other-side.phpt
[edit]
[-] socket-ipv4loop.phpt
[edit]
[-] class-static-properties.phpt
[edit]
[-] closure-delayed-include.phpt
[edit]
[-] workers-ok-unstack.phpt
[edit]
[-] include_interface_constant.phpt
[edit]
[-] counting-members.phpt
[edit]
[-] inherit-non-closures.phpt
[edit]
[-] inherited-anon-class.phpt
[edit]
[-] waiting-timeouts.phpt
[edit]
[-] gone.phpt
[edit]
[-] static-resolution.phpt
[edit]
[-] anon-unbound-use-guards.phpt
[edit]
[-] unstack-running.phpt
[edit]
[-] crazy-refcounting-stuff.phpt
[edit]
[-] complex-statics.phpt
[edit]
[-] graceful-fatalities.phpt
[edit]
[-] socket-connect-params-af-inet.phpt
[edit]
[-] private-class-constant-fetching.phpt
[edit]
[-] display-startup-errors-output.phpt
[edit]
[-] global-constants.phpt
[edit]
[-] return-types.phpt
[edit]
[-] constant-ast-copy.phpt
[edit]
[-] functions.phpt
[edit]
[-] socket-unixloop.phpt
[edit]
[-] closures-as-members.phpt
[edit]
[-] staticmethods.phpt
[edit]
[-] exception-handler-options.phpt
[edit]
[-] inherited-anon-class-outside-context.phpt
[edit]
[-] legacy-ctor.phpt
[edit]
[-] volatile-arrays.phpt
[edit]
[-] recv-overload.phpt
[edit]
[-] socket-bind.phpt
[edit]
[-] socket-construct.phpt
[edit]
[-] trait-aliases.phpt
[edit]
[-] stateful-fatalities.phpt
[edit]
[-] socket-getpeername-af-unix.phpt
[edit]
[-] socket-read-type.phpt
[edit]
[-] volatile-nested.phpt
[edit]
[-] workers-default-collector.phpt
[edit]
[-] no-cloning.phpt
[edit]
[-] exception-handler-caught-nested.phpt
[edit]
[+]
assets
[-] socket-connect-params-af-unix.phpt
[edit]
[-] isset-unset.phpt
[edit]
[-] class-defaults.phpt
[edit]
[-] exception-handler-fail.phpt
[edit]
[-] doc-comments.phpt
[edit]
[-] explicit-cast-arrays.phpt
[edit]
[-] static-inheritance-unexpected-null.phpt
[edit]
[-] run-time-cache-corruption.phpt
[edit]
[-] anon-unbound-inherited.phpt
[edit]
[-] thread.phpt
[edit]
[-] traits-scope.phpt
[edit]
[-] child-to-parent-class-copying-helper.php
[edit]
[-] socket-select-win32.phpt
[edit]
[-] threaded_valid_tsrmls.phpt
[edit]
[-] class-static-properties-order-dependencies-inheritance.phpt
[edit]
[-] merge-non-threaded.phpt
[edit]
[-] exception-handler.phpt
[edit]
[-] isset-empty-compat.phpt
[edit]
[-] ini.phpt
[edit]
[-] anon-interceptors.phpt
[edit]
[-] binding.phpt
[edit]
[-] workers-no-unstack.phpt
[edit]
[-] exception-handler-caught-uncaught.phpt
[edit]
[-] socket-getpeername-af-inet.phpt
[edit]
[-] normal-reads.phpt
[edit]
[-] socket-sentto-recvfrom-ipv4-udp.phpt
[edit]
[-] child-to-parent-class-copying.phpt
[edit]
[-] threaded-extend-abstract.phpt
[edit]
[-] socket-getoption.phpt
[edit]
[-] workers-no-stack.phpt
[edit]
[-] shift-pop.phpt
[edit]
[-] pools.phpt
[edit]
[-] callstatic-etc.phpt
[edit]
[-] socket-sentto-recvfrom-unix.phpt
[edit]
[-] no-inheritance-anon-class.phpt
[edit]
[-] class-static-properties-double-inheritance.phpt
[edit]
[-] iterator-funcs.phpt
[edit]
[-] volatile-objects.phpt
[edit]
[-] merging-range.phpt
[edit]
[-] merging-members.phpt
[edit]
[-] runtime-inheritance-volatile.phpt
[edit]
[-] pthreads-inherit-none-class-constant-inherited.phpt
[edit]
[-] anon-bound-inherited.phpt
[edit]