note 91643 added to function.readline

From: Date: Sun, 21 Jun 2009 09:00:53 +0000
Subject: note 91643 added to function.readline
Groups: php.notes 
Request: Send a blank email to php-notes+get-157190@lists.php.net to get a copy of this message
I wanted a function that would timeout if readline was waiting too long... this works on php CLI on linux: <? function readline_timeout($sec, $def) { return trim(shell_exec('bash -c ' . escapeshellarg('phprlto=' . escapeshellarg($def) . ';' . 'read -t ' . ((int)$sec) . ' phprlto;' . 'echo "$phprlto"'))); } ?> Just call readline_timeout(5, 'whatever') to either read something from stdin, or timeout in 5 seconds and default to 'whatever'. I tried just using shell_exec without relying on bash -c, but that didn't work for me, so I had to go the round about way. ---- Server IP: 64.71.164.2 Probable Submitter: 69.140.141.187 ---- Manual Page -- http://www.php.net/manual/en/function.readline.php Edit -- https://master.php.net/note/edit/91643 Del: integrated -- https://master.php.net/note/delete/91643/integrated Del: useless -- https://master.php.net/note/delete/91643/useless Del: bad code -- https://master.php.net/note/delete/91643/bad+code Del: spam -- https://master.php.net/note/delete/91643/spam Del: non-english -- https://master.php.net/note/delete/91643/non-english Del: in docs -- https://master.php.net/note/delete/91643/in+docs Del: other reasons-- https://master.php.net/note/delete/91643 Reject -- https://master.php.net/note/reject/91643 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157190) next »