Rayyan Jawaid
Rayyan Jawaid

Reputation: 88

How to use threads in PHP 7.0

I've created php-cli.ini, added pthread extension there and set memory limit to 3 gb. But when I'am trying to launch thread script I got this:

PHP Fatal error:  Uncaught RuntimeException: cannot start my_thread, out of resources in 
C:\xampp\htdocs\app90\start_threads.php:160

Stack trace:
#0 C:\xampp\htdocs\app90\start_threads.php(160): Thread->start()
#1 {main}
  thrown in C:\xampp\htdocs\app90\start_threads.php on line 160

Fatal error: Uncaught RuntimeException: cannot start my_thread, out of resources
 in C:\xampp\htdocs\app90\start_threads.php:160

help required thanks in advance.

Upvotes: 1

Views: 553

Answers (1)

Arsalan Akhtar
Arsalan Akhtar

Reputation: 389

Essentially, this is caused by pthread_create returning EAGAIN: It means that the system lacks resources to create another thread, or that the system imposed limit on the maximum number of threads (in a process, or system wide) has been reached.

This can be caused by two things, the purposeful use of more threads than a process can handle simultaneously as a result of the way some software is designed, or more perniciously, as a result of less than graceful joining of threads.

If you only seem to hit such errors sometimes, it would suggest the latter is going on; Be sure to cleanup (explicitly join) threads you are done with to make behaviour predictable.

Upvotes: 1

Related Questions