fread timeout in PHP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

fread timeout in PHP

Gary Richardson
Hi,

I've run into a problem in the PHP client:

=================
public function readFrame ()
    {  
        if (!$this->hasFrameToRead()) {
            return false;
        }

        $rb = 1024;
        $data = '';
        $end = false;

        do {
            $read = fread($this->_socket, $rb);
            if ($read === false) {
                $this->_reconnect();
                return $this->readFrame();
            }
            $data .= $read;
            if (strpos($data, "\x00") !== false) {
                $end = true;
                $data = rtrim($data, "\n");
            }
            $len = strlen($data);
        } while ($len < 2 || $end == false);
================

I have $stomp->setReadTimeout(1,0). My client is checking for a single message at a time. With the above code, I'm guessing ActiveMQ isn't always sending a terminator because it blocks on the fread call.

To get around this, I've added in:

--- Stomp.php.orig      2010-02-04 20:13:32.000000000 -0800
+++ Stomp.php   2010-02-04 20:25:52.000000000 -0800
@@ -525,7 +525,8 @@
         $rb = 1024;
         $data = '';
         $end = false;
-        
+      
+       stream_set_timeout($this->_socket, $this->_read_timeout_seconds, $this->_read_timeout_milliseconds);
         do {
             $read = fread($this->_socket, $rb);
             if ($read === false) {


which seems to solve the problem for me.

Thanks.