From: Janusz Dobrowolski Date: Thu, 6 Sep 2012 17:27:44 +0000 (+0200) Subject: Improved error handling in printer class. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=a9b90cd60d98e462a853faf8acd29b0340b6c98e;p=textcart.git Improved error handling in printer class. --- diff --git a/includes/remote_url.inc b/includes/remote_url.inc index fb0c134..186b4f9 100644 --- a/includes/remote_url.inc +++ b/includes/remote_url.inc @@ -60,11 +60,13 @@ function url_get_contents($url, $timeout=10) "Referer: http://$host\r\n\r\n"); // retrieve the response from the remote server - $len =0; + $unblocked=0; + while ($line = fread($fp, 4096)) { $response .= $line; - if ($host=='localhost') + if ($host=='localhost' && !$unblocked++) stream_set_blocking($fp, 0); // just after connection switch to nonblocking mode + usleep(10); } fclose( $fp ); diff --git a/reporting/includes/printer_class.inc b/reporting/includes/printer_class.inc index 1b5a14e..93bf06a 100644 --- a/reporting/includes/printer_class.inc +++ b/reporting/includes/printer_class.inc @@ -34,9 +34,9 @@ class remote_printer { // if($ret) return $ret; //Open a new connection to send the control file and data. - $stream = fsockopen("tcp://".$this->host, $this->port, $errNo, $errStr, $this->timeout); + $stream = @fsockopen("tcp://".$this->host, $this->port, $errNo, $errStr, $this->timeout); if(!$stream){ - return _('Cannot open connection to printer'); + return _('Cannot open connection to printer').":
$errStr"; } if (!isset($_SESSION['_print_job'])) { $_SESSION['print_job'] = 0; @@ -95,9 +95,9 @@ class remote_printer { // Print all waiting jobs on remote printer queue. // function flush_queue($queue){ - $stream = fsockopen("tcp://".$this->host, $this->port,$errNo, $errStr, $this->timeout); + $stream = @fsockopen("tcp://".$this->host, $this->port,$errNo, $errStr, $this->timeout); if (!$stream){ - return _('Cannot flush printing queue'); + return _('Cannot flush printing queue').":
$errStr"; // .':
' . $errNo." (".$errStr.")"; return 0 (success) even on failure } else { //Print any waiting jobs