DEV Community

Using Asynchronous Processes in PHP.

Wisdom Ebong on February 08, 2020

For most programs written in PHP, its sole purpose is to execute a simple process consisting of multiple tasks, where the tasks must be executed in...
Collapse
 
damlight profile image
Daei_F

This is great. I hope PHP7 finally brings native async, they've made so many advances but async is something so many people really wants from it

Collapse
 
zexias profile image
Matheus Faustino

for async and concurrent code I really like Amp project. It's really good and easy to integrate: amphp.org/

Collapse
 
johnsamuelob profile image
John Samuel Obinna

Awesome Post 😎

Collapse
 
opensaucedeveloper profile image
Afolayan Oluwaseun Raphael

Thank you very much for sharing this✨. Definable learnt a lot as regards async operations.

Collapse
 
arunnabraham profile image
arunnabraham

Async is one of the needy feature inbuilt to PHP. As per Nikita this feature wont come anytime soon. Which is sad. However if you want performance in PHP Asynchronus Programming, defenitly checkout SwoolPHP which has been less noticed over years since its inception. Its features are inspired from NodeJS and Golang. Performance is far better than NodeJS maybe kind of closer to Go.

Instead of library like ReactPHP or AmPHP it is written in C as PHP extension. Yet its feature rich like these librarires.

Checkout their links

swoole.co.uk/

github.com/swoole/swoole-src

swoolebook.com/

Collapse
 
technoexpress profile image
L. Stubbs

How about something actually more native like, and simpler to use, all pure PHP base.

symplely.github.io/coroutine/

Collapse
 
cvar1984 profile image
Bellatrix Lugosi

Hmm, i prefer amp/parallel because it works for both web and console

Collapse
 
efeferrari profile image
franco

I tried the example, but with this result:

Argument 1 passed to await() must be an instance of Spatie\Async\Pool, instance of Spatie\Async\Process\SynchronousProcess given.

Collapse
 
roelofjanelsinga profile image
Roelof Jan Elsinga

I needed to see this post! I've been struggling with this and finally just switched to using Golang. This definitely seems to be something I could have used! Great post! ⚑

Collapse
 
mehdifathi profile image
Mehdi Fathi

I think asynchronous doesn't fitt with Php.may be you can use another language to implement asynchronous as Node.js or Golang. If you want to see deep your job in async PHP is not good for you

Collapse
 
aldora profile image
Aldora

I can't use your second code block which use spatie\async produce different result, it's still 2,4,6,8,10

Collapse
 
aldora profile image
Aldora

Sorry, it turns out to be my homestead enviroment problem

Collapse
 
fadhilriyanto profile image
Fadhil Riyanto

This is great!!

Collapse
 
dkushwah profile image
Deependra kushwah

Good one

Collapse
 
hasnatbabur profile image
Hasnat Babur • Edited

Queues are more useful in modern world instead the 'asynchronous' hype. Think about developers efficiency than machines efficiency. Laravel has great Queues support!

Collapse
 
igormelo profile image
Igor Melo

Nice post.
Could you add syntax highlighting?