- changed status to on hold
Postgres and event issue
I want to add read event to pg_socket with event extension both don't accept resource of pg_socket but stream_select works well
For simplicity I write test script with well known library called reactphp/event-loop
if you run test script using event extension , this warning shown and there is no read event
PHP Warning: Event::add(): Epoll ADD(1) on fd 30584288 failed. Old events were 0; read change was 1 (add); write change was 0 (none); close change was 0 (none): Bad file descriptor in vendor/react/event-loop/src/ExtEventLoop.php on line 259 PHP Warning: Event::add(): Failed adding event in vendor/react/event-loop/src/ExtEventLoop.php on line 259
Test script:
$loop = React\EventLoop\Factory::create();
$connection = pg_connect("host=localhost port=5432 dbname=mary");
$socket = pg_socket($connection);
$loop->addReadStream($socket , function (){
echo "READ EVENT\n";
});
pg_send_query($connection , "select * from authors;");
Actual result:
PHP Warning: Event::add(): Epoll ADD(1) on fd 30584288 failed. Old events were 0; read change was 1 (add); write change was 0 (none); close change was 0 (none): Bad file descriptor in vendor/react/event-loop/src/ExtEventLoop.php on line 259 PHP Warning: Event::add(): Failed adding event in vendor/react/event-loop/src/ExtEventLoop.php on line 259
Comments (11)
-
repo owner -
reporter Thanks for your reply
I will send you a complete test script asap . simple and with no dependency to repro issue
-
reporter See https://github.com/reactphp/event-loop/issues/121 , It is hard to repro issue But if you install
react/event-loop
with composer and run this code<?php require_once 'vendor/autoload.php'; $loop = React\EventLoop\Factory::create(); $connection = pg_connect("host=localhost port=5432 dbname=mary"); $socket = pg_socket($connection); $loop->addReadStream($socket , function (){ echo "READ EVENT\n"; }); pg_send_query($connection , "select * from authors;"); $loop->run();
We have Segmentation fault on PHP 7.0
-
reporter Please see this comment
https://github.com/reactphp/event-loop/issues/121#issuecomment-347019604
Here is source code that use your library https://github.com/reactphp/event-loop/blob/master/src/ExtEventLoop.php
-
reporter @osmanov Please reply
-
repo owner - changed status to open
-
repo owner @Socketman2016 I will try to reproduce and fix the issue, if it is fixable from the source of Event. But I'm very busy these days, and I will not promise anything.
Right now, I can only say that Event actually does not support postgres socket resources. Look at this function, for instance.
As always, pull requests are welcome.
-
repo owner - changed status to wontfix
I have finally tested Event with
pgsql
extension. As I guessed,Event
extension does not supportpgsql
resources =) And theEvent::add
method rightfully returnsfalse
. However,React\EventLoop\ExtEventLoop::subscribeStreamEvent
method ignores the returned value.I would have suggested to add support for the "PostgreSQL link" resource into Event, if
pgsql
had a public API for accessing the resource internals. -
reporter @osmanov How can I chat you?? Do you have WhatsApp account or any other way I contact you directly??
-
repo owner @Socketman2016 You can reach me via Google Hangouts. But it's 23:20 here, so it's likely that I'll go offline very soon.
-
reporter @osmanov please check your hangouts
- Log in to comment
Is that the complete test script? I don't see how the event loop is launched, and how the socket variable is preserved until the loop finishes.
I'm not very familiar with ReactPHP. Probably, it launches the event loop implicitly in the shutdown handler. If it's so, your
$socket
variable gets destroyed before the event loop tries to access it. So you should preserve all variables (such as$socket
) that are supposed to be used in the event handlers until they are no longer needed.