reactphp/stream

$stream->on('connection') not triggering on ldap_bind

tokidoki11 opened this issue · 5 comments

This is the continue of problem #48

I updated my gist here https://gist.github.com/tokidoki11/668a3a6f0888c05995b5f45bb2439322

I tried to use ldap_bind, but the process seems to be stuck. The On Connection event is not triggering at all.

What I have done:

  1. Try to ldapsearch via another terminal, it works.. (this only for proof of concept, I need to do this at the same terminal)
  2. Try to make class of thread, and then run the thread on the create callback
create(60000,function()
{
    $thread = new LDAPSearchThread(<ID>);
    $thread->run();
});
class LDAPSearchThread extends Thread
{

    private $searchID;
    private $searchData;

    public function __construct($searchID)
    {
        $this->searchID = $searchID;
    }

    public function run()
    {
        echo "running thread";
        //creaete ldap coonection and bind //stuck also
    }

}

It's weird though, if I invoke fsockopen, the connection event will trigger.
If I invoke fsockopen then ldap_bind, the connection event will not trigger

@clue maybe you could give me an advise? :)

clue commented

I'm not sure I follow you code, so perhaps you may help by reducing this to the bare minimum to highlight the issue you're seeing?

As a general rule of thumb, anything that is blocking (such as your LDAP query) does not work well with React. Unless you feel like implementing an async LDAP client on top of React PHP (which I'd love to see), I'd suggest moving the blocking parts to a separate process and using the ChildProcess component for IPC.

Basically i want to query ldap via the proxy server i made on port 60000.
So everything on react should be on non-blocking? if so, fsockopen run successfully FYI

clue commented

So everything on react should be on non-blocking?

Yes, also see https://github.com/reactphp/react/wiki/FAQ#how-can-i-use-blocking-functions

You may get away with blocking for small periods of time (such a local fsockopen), but these are generally considered experimental and unsupported and better alternatives usually exist, such as the SocketClient in this case.

I guess I cant do much....