php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46919 Multi threading
Submitted: 2008-12-21 19:39 UTC Modified: 2013-01-16 21:54 UTC
Votes:43
Avg. Score:4.8 ± 0.7
Reproduced:30 of 32 (93.8%)
Same Version:21 (70.0%)
Same OS:25 (83.3%)
From: n0valyfe at gamergrid dot net Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.2.8 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-12-21 19:39 UTC] n0valyfe at gamergrid dot net
Description:
------------
Would it be possible to add some sort of multithreading into PHP, say a new thread is created via a function, to execute a function or object method in a new thread.

Keeping the scope intact, so that $this and global vars work inside that function in another thread.

I think this would benefit PHP in many ways, for instance a script wouldnt "hang" when executing something that can take a while, it can just open a new thread.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-01 15:05 UTC] speedy dot spam at gmail dot com
What would be really great to have is something similar to classic pcntl_clone() linux kernel function on the PHP level, accepting a function to be executed as a parameter and sharing all the variables/state with the primary and other created threads.

Locking could be done with a simple and optional use of mutexes on the application level, if one needs to view fully consistent state of a certain variable / array. (ie. otherwise, foreach() loop while writing to an array in the other thread might not see some recently added entries)

As an idea, on the internal implementation side, copy-on-write semantics could be used with read-only operations seeing the previous version while the write/modify operation is executed on a copy.

Even if unstable at first (marked as experimental or some such), it would be a good starting point for making PHP thread-safe, re-entrant, and multi-core compatible.
 [2012-03-21 22:09 UTC] jose dot nobile at gmail dot com
How many year the PHP community will wait for <?PHP new Thread?>
 [2013-01-16 21:34 UTC] invictible at live dot co dot uk
I believe, that this would be a excellant addition to PHP as I've run into many situation where multi-threading would have made it much more performant than simply running everything in one thread where a single function taking it's time or other lengthy tasks can have a significant impact on the time it takes the script to run.
 [2013-01-16 21:54 UTC] rasmus@php.net
This is not going to happen in PHP core, but it can be done through an extension. 
One example is here: http://pecl.php.net/package/pthreads
 [2013-01-16 21:54 UTC] rasmus@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 11:01:33 2024 UTC