# Multithreading: I'm not complaining--I did something! (and it works on Windows)

- Thread: https://externals.io/message/49486
- Original archive: https://news-web.php.net/php.internals/49486
- Started by Alec on 2010-08-23T03:12:05+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #49486 — Alec — 2010-08-23T03:12:05+00:00

URL: https://externals.io/message/49486#49486

Hi guys, long time reader, 2nd time poster. I realize there is 
much...bitterness about multithreading in PHP. I feel it is important, 
but I know others don't. I just wanted to write and say that I have made 
Moriyoshi Koizumi's php_threading ( 
http://github.com/moriyoshi/php-src/blob/PHP_5_3-threading/ext/threading/ ) 
available for Windows!

I converted all of the code to pthreads instead of GNU Pth so that 
pthreads-win32 could be used on Windows. I am quite proud to say that 
converted it all from Pth to pthreads by only reading the documentation 
and never actually building it with GCC--and it worked the first time. 
Well, not quite, but those were just dependency and other errors (like 
that stupid 32 bit time thing)--all the pthreads stuff worked first time 
(that is the first time I have said that about anything C related :D)! I 
just converted it all in good ol' Notepad++ and then made VC2008 project.


QUICK REPO, SOURCE AND BINARY LOCATION
--------------------------------------
My repo is at: http://github.com/alecgorge/php_threading

I push the compiled DLL so you can always find the latest compiled 
version at: 
http://github.com/alecgorge/php_threading/tree/master/binaries/Release/

If you are interested in a "stable" version I will post them at:
http://github.com/alecgorge/php_threading/downloads


HELPING
-------
For those of you interested in helping, go ahead! The repo has 
everything you need to build except for the Windows SDK and VC2008. It 
has all the PHP headers, PHP libraries, pthreads-win32 headers and 
pthreads-win32 libraries you need to compile yourself (in the deps folder).

Now for the bad part: it is really ****ing buggy. For example: most of 
the samples work. Some never exit. Some crash. But overall it is 
"stable" enough just to use for a quick personal project with PHP.

I think the biggest bug is that usleep breaks (whoops).


Here is my comments by sample (found in source/samples/)
--------------------------------------------------------
01: Works well except for the crashing at the end.
02: Doesn't work at all. But I have never worked with sockets in PHP so 
maybe someone wants to lend a hand?
03: Goes with example02. Doesn't work at all and I have no clue why.
04: Demos sending content to threads. It works except it never exits!


What I would like:
------------------
- Someone with real experience working with threads and C to give me a 
hand tracking down some of the bugs. I am willing to fix things myself 
but I am having trouble locating things!

- Linux people to help me out. I have no Linux box handy so tell me if 
this build works with Linux. I tried to make sure I didn't break 
anything by using conditional comments--and I think it works? (see: 
http://github.com/alecgorge/php_threading/blob/master/source/threading.c#L369 
for an example)

- Linux people to give me build instructions. You can see Moriyoshi's 
original instructions at 
http://github.com/moriyoshi/php-src/blob/PHP_5_3-threading/ext/threading/README



Sorry for the wall of text, I just had a very productive 12 hours of 
coding and wanted to tell the world :D

-Alec

---

## #49487 — Alec — 2010-08-24T00:35:29+00:00

URL: https://externals.io/message/49486#49487 · In reply to: #49486

As an update, I fixed the crashing bug, the usleep bug (I don't know if 
it was really a bug, probably just a misinterpretation on my part), and 
the hanging bug. I fixed thread joining. I updated the samples and I am 
working on example05.php that will demo cURL!

Thanks to Tom R. who contacted me off the mailing list with a patch for 
the crash that would have taken me forever to track down!

-Alec


> Hi guys, long time reader, 2nd time poster. I realize there is
> much...bitterness about multithreading in PHP. I feel it is important,
> but I know others don't. I just wanted to write and say that I have made
> Moriyoshi Koizumi's php_threading (
> http://github.com/moriyoshi/php-src/blob/PHP_5_3-threading/ext/threading/ )
> available for Windows!
>
> I converted all of the code to pthreads instead of GNU Pth so that
> pthreads-win32 could be used on Windows. I am quite proud to say that
> converted it all from Pth to pthreads by only reading the documentation
> and never actually building it with GCC--and it worked the first time.
> Well, not quite, but those were just dependency and other errors (like
> that stupid 32 bit time thing)--all the pthreads stuff worked first time
> (that is the first time I have said that about anything C related :D)! I
> just converted it all in good ol' Notepad++ and then made VC2008 project.
>
>
> QUICK REPO, SOURCE AND BINARY LOCATION
> --------------------------------------
> My repo is at: http://github.com/alecgorge/php_threading
>
> I push the compiled DLL so you can always find the latest compiled
> version at:
> http://github.com/alecgorge/php_threading/tree/master/binaries/Release/
>
> If you are interested in a "stable" version I will post them at:
> http://github.com/alecgorge/php_threading/downloads
>
>
> HELPING
> -------
> For those of you interested in helping, go ahead! The repo has
> everything you need to build except for the Windows SDK and VC2008. It
> has all the PHP headers, PHP libraries, pthreads-win32 headers and
> pthreads-win32 libraries you need to compile yourself (in the deps folder).
>
> Now for the bad part: it is really ****ing buggy. For example: most of
> the samples work. Some never exit. Some crash. But overall it is
> "stable" enough just to use for a quick personal project with PHP.
>
> I think the biggest bug is that usleep breaks (whoops).
>
>
> Here is my comments by sample (found in source/samples/)
> --------------------------------------------------------
> 01: Works well except for the crashing at the end.
> 02: Doesn't work at all. But I have never worked with sockets in PHP so
> maybe someone wants to lend a hand?
> 03: Goes with example02. Doesn't work at all and I have no clue why.
> 04: Demos sending content to threads. It works except it never exits!
>
>
> What I would like:
> ------------------
> - Someone with real experience working with threads and C to give me a
> hand tracking down some of the bugs. I am willing to fix things myself
> but I am having trouble locating things!
>
> - Linux people to help me out. I have no Linux box handy so tell me if
> this build works with Linux. I tried to make sure I didn't break
> anything by using conditional comments--and I think it works? (see:
> http://github.com/alecgorge/php_threading/blob/master/source/threading.c#L369
> for an example)
>
> - Linux people to give me build instructions. You can see Moriyoshi's
> original instructions at
> http://github.com/moriyoshi/php-src/blob/PHP_5_3-threading/ext/threading/README
>
>
>
>
> Sorry for the wall of text, I just had a very productive 12 hours of
> coding and wanted to tell the world :D
>
> -Alec

---

## #49503 — Alec — 2010-08-24T23:33:07+00:00

URL: https://externals.io/message/49486#49503 · In reply to: #49487

Another update! Added a new function and a new argument to a function. 
Check out example05.php for an example using curl. I am working on 
getting example02 and 03 to work. There is a bug when parameters are 
streams, the program crashes. Fun.

-Alec


> As an update, I fixed the crashing bug, the usleep bug (I don't know if
> it was really a bug, probably just a misinterpretation on my part), and
> the hanging bug. I fixed thread joining. I updated the samples and I am
> working on example05.php that will demo cURL!
>
> Thanks to Tom R. who contacted me off the mailing list with a patch for
> the crash that would have taken me forever to track down!
>
> -Alec
>
> 
> > […]
