parallel
parallel copied to clipboard
Pooling with parallel extension?
Hi,
I need to execute in parallel various threads that communicate with PDO to fetch a pool of X calls details from database and rate them in parallel.
Where can I found some real example to achieve this with parallel extension?
Regards
Checkout the first user contributed note: https://www.php.net/manual/en/parallel.run.php
Hey @scramatte 👋
you'd have two options:
- fetch all the data from the database in your main thread, start worker threads and pass in part of the data each thread should process
- skim over the data and assign each thread a range it should process, letting the threads fetch the data from the database on their own
I did something like the second option in https://dev.to/realflowcontrol/processing-one-billion-rows-in-php-3eg0#can-we-make-it-even-faster The downside is that you'd need to open multiple (as in number of threads) connection to your database. I would think that using persistent connections could help (less "new" connections, but reusing unused, but already established connections). Anyway, you need to be aware that your database might have connection limits that you could reach, depending on the number of threads (and hence open connections).
Hope this helps.