Skip to content

Commit

Permalink
Merge pull request #349 from Stenerson/development
Browse files Browse the repository at this point in the history
Add timeout parameter to NetworkPrintConnector
  • Loading branch information
mike42 committed May 13, 2017
2 parents 88a0115 + a19ed77 commit 9bbc673
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Mike42/Escpos/PrintConnectors/NetworkPrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ class NetworkPrintConnector extends FilePrintConnector
*
* @param string $ip IP address or hostname to use.
* @param string $port The port number to connect on.
* @param string $timeout The connection timeout, in seconds.
* @throws Exception Where the socket cannot be opened.
*/
public function __construct($ip, $port = "9100")
public function __construct($ip, $port = "9100", $timeout = false)
{
$this -> fp = @fsockopen($ip, $port, $errno, $errstr);
// Default to 60 if default_socket_timeout isn't defined in the ini
$defaultSocketTimeout = ini_get("default_socket_timeout") ?: 60;
$timeout = $timeout ?: $defaultSocketTimeout;

$this -> fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
if ($this -> fp === false) {
throw new Exception("Cannot initialise NetworkPrintConnector: " . $errstr);
}
Expand Down

0 comments on commit 9bbc673

Please sign in to comment.