I am developing a php application with laravel. In my application I need to do some data fetching from a number of servers. In order to speedup the results I have to send those requests in the same time. I've found laravel queue but the problem is that the I need to get information back from the queue. Another solution is php pthreads but I'm having a very hard time installing it. Is there any way (multithreading / multiprocessing) to do seprate jobs async.
Asked
Active
Viewed 3,864 times
0
-
Yes, with Pthreads. If you are having troubles installing Pthreads you may look for tutorials or help on google. Or if you have a specific problem, seek help on Super User. – Charlotte Dunois Jul 24 '16 at 13:41
1 Answers
2
Beyond the possible duplicate, PHP is synchronous by nature. Asynchronous programming is possible, but not necessarily simple enough to be covered by one stackoverflow answer. You have already tried pthreads which is the most extensive multithreading library in my opinion.
You can do asynchronous requests with CURL: http://php.net/manual/en/function.curl-multi-init.php
You can use pcntl to fork processes: http://php.net/manual/en/function.pcntl-fork.php

Devon Bessemer
- 34,461
- 9
- 69
- 95
-
the thing is that there is two way in multi tasking for php: 1. multi threading 2. multi processing which one is better? If I want to create a new process how can I send data back to the main process – Alireza Jul 25 '16 at 05:47