21 de septiembre de 2013

PHP: Implementing timed-out remote calls

 In the PHP programming languages there are a set of method calls that might make you web application unresponsive. For example, in the case of requesting a file from a remote site, the resource might not exist, be broken or be just too large.

In order to avoid the unresponsive, halt or idle scenarios, all web applications must be designed to respond in the time interval it takes for a user to decide whether to give up or try again. Here's one work around that maybe helpful for PHP users.

   $get_resource= function( $uri, $timeout=2 ){
     set_time_limit( $timeout );
     return get_file_contents( $uri );
   };
   $image= $get_resource( 'http://tinyurl.com/nkkgk8d' );