note 118620 added to function.stream-set-timeout

From: Date: Sun, 10 Jan 2016 13:15:30 +0000
Subject: note 118620 added to function.stream-set-timeout
Groups: php.notes 
Request: Send a blank email to php-notes+get-204633@lists.php.net to get a copy of this message
If the timeout fails, because the server remains completely silent, one may have to add stream_select() to make the timeout work. This may be much more efficient that a non-blocking reading operation. <?php stream_set_timeout($c, $timeout); $data = ''; $stR = array($this->smtp_conn); $stW = null; while (is_resource($c) && !feof($c)) { if (!stream_select($stR, $stW, $stW, $timeout)) { trigger_error('Timeout'); break; } $str = fgets($c, 515); $data.= $str; // Handling of "traditional" timeout $info = stream_get_meta_data($c); if ($info['timed_out']) { trigger_error('Timeout'); break; } } ?> Background: We had issues with a SMTP server that was addresses unencrypted while expecting TLS encryption. The stream_set_timeout() alone did not work as expected and the script hung for an hour or more. ---- Server IP: 72.52.91.14 Probable Submitter: 46.128.22.170 ---- Manual Page -- http://php.net/manual/en/function.stream-set-timeout.php Edit -- https://master.php.net/note/edit/118620 Del: integrated -- https://master.php.net/note/delete/118620/integrated Del: useless -- https://master.php.net/note/delete/118620/useless Del: bad code -- https://master.php.net/note/delete/118620/bad+code Del: spam -- https://master.php.net/note/delete/118620/spam Del: non-english -- https://master.php.net/note/delete/118620/non-english Del: in docs -- https://master.php.net/note/delete/118620/in+docs Del: other reasons-- https://master.php.net/note/delete/118620 Reject -- https://master.php.net/note/reject/118620 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204633) next »