How to multi-thread using codeigniter famework(PHP)?

南楼画角 提交于 2019-12-25 04:16:01

问题


I am using codeigniter framework. And i am searching for a best practice to multi-thread using MVC framework of codeigniter.

I am thinking of creating a class in which all the functions will be written to run in a different independent thread.

Please suggest me techniques to multi thread using codeigniter's MVC framework.


回答1:


You can't do multi-threading directly with PHP. Every page load is handled by a single thread.

If you want the value of function foo() to be passed to function bar() but in a multi-threaded kind of way, you could emulate it with a job queue like Resque or RabbitMQ.

But saying you want multi-threaded PHP is like saying you want a motorbike with four wheels.




回答2:


Here is a php multi thread library to fork a process into a separate thread, which i am using to exactly what you describe in mcodeigniter

https://github.com/motanelu/php-thread




回答3:


php-thread doesn't provide real threading, it just forks the process and results in multiprocessing.

If you want real threading in php, use pthreads. But be aware of the pitfalls!

Important note to read

  • https://gist.github.com/krakjoe/6437782


来源:https://stackoverflow.com/questions/29241050/how-to-multi-thread-using-codeigniter-fameworkphp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!