Closed LanKing closed 3 years ago
Hi!
Well, we don't encourage you to join coroutine with laravel way. In our experience you might get some conflicts (as the one that you're experiencing) at this moment.
This package was created to improve your app loading (by pre-loading it in memory). Of course you can use coroutines (and I personally think that database pool is the best example to use coroutines) but you'll need understand a lot of concepts of concurrency.
Try to check:
https://www.swoole.co.uk/docs/modules/pdo-connection-pool https://www.swoole.co.uk/docs/modules/swoole-async-mysql-client
The best book of swoole with a lot of concurrency examples
Please provide your PHP and Swoole version. (
php -v
andphp --ri swoole
)Please provide your Laravel/Lumen version.
Laravel "v7.29.3
Which release version of this package are you using?
v2.6.68
What did you do? If possible, provide a recipe for reproducing the error.
I am trying to work with mysql in Laravel out-of-the-box (lol). My way was the next:
First of all I tried to set 'mysql-coroutine' driver as default mysql driver in config/database.php ('mysql' section). But this does not works, because co-routine must be started in the event-loop ⭕
So, then I created middleware for all my api routes (they really need to be async) with the next instruction:
DB::setDefaultConnection('mysql-coroutine');
and it worked!❓ My main question: Is this is a correct way?
Now it works but sometimes I got:
Uncaught Swoole\Error: Socket#19 has already been bound to another coroutine#3026, reading of the same socket in coroutine#3027 at the same time is not allowed in /home/dontmatters/www/vendor/swooletw/laravel-swoole/src/Coroutine/PDO.php:262
As I understand, to fix this I need mysql connection pool? Please, give me an advice 🙏
What did you expect to see? Stable async database work.
What did you see instead? Sometimes crashes.