3

I’m working on a project for my graduation and I need to enable pthreads in PHP because I need multithreading. I used a tutorial, but I get this error: Fatal error class 'Thread' not found in….

I searched the web for help on how to enable pthreads, but nothing helped. I’m using PHP version 5.4.7.

Palec
  • 12,743
  • 8
  • 69
  • 138
Antreas Apostolou
  • 315
  • 2
  • 9
  • 17

3 Answers3

3

A user suffering the same error has posted the solution on github: https://github.com/krakjoe/pthreads/issues/154

The short of it is you have to add pthreadVC2.dll to Apache configuration ... I wasn't aware of this, I don't use Windows ...

That should get you sorted ...

Joe Watkins
  • 17,032
  • 5
  • 41
  • 62
0

the dlls should be compatible with your php version

check this answer pthread not working in php

Community
  • 1
  • 1
-4

There is no 'threading' in PHP. You can fork a new 'process' using pctnl_fork(), however there is no built in shared memory between the two processes (youll have to implement shmop() or a socket server setup to communicate between processes). Also, pcntl_* is only usable on linux setups, not windows.

kwolfe
  • 1,663
  • 3
  • 17
  • 27
  • Then whats's the usage of pthreads???In php there is a whole documentation talking about them...http://php.net/manual/en/book.pthreads.php Is your suggestion about using pctnl_fork() tested?(some example)? – Antreas Apostolou Aug 14 '13 at 17:28
  • i have implemented a search engine system with multiple online users, and my teacher now wants every time the search button isset to start a new proccess.So if the button clicked by different users we are talking about mulriple threads...i dont know how excactly i this coz as you said there is no threads in php..im to complicated.. – Antreas Apostolou Aug 14 '13 at 22:24
  • Whoa. This is not necessary, at all. A new process is launched each time someone opens the site. Each session (browser) is completely separate and will not occupy the same memory space as other requests that happen to come in at the same time. Just write the script out to work on what you think would be one mcahine and it will work on all. – kwolfe Aug 15 '13 at 14:16