forked from BrewPi/brewpi-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket_open.php
30 lines (27 loc) · 920 Bytes
/
socket_open.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
require_once('configuration.php');
function open_socket()
{
$isWindows = defined('PHP_WINDOWS_VERSION_MAJOR');
$useInetSocket = getConfig("useInetSocket", $isWindows);
if ($useInetSocket)
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
else
$sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
if (!($sock === false))
{
if(
((!$useInetSocket) && socket_connect($sock, "$GLOBALS[scriptPath]/BEERSOCKET"))
|| (($useInetSocket) && socket_connect($sock, getConfig("scriptAddress", "localhost"), getConfig("scriptPort",6332))))
{
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0));
}
else{
socket_close($sock);
if (getConfig('debug', false))
echo "Socket connection failed: " . socket_strerror(socket_last_error($sock));
}
}
return $sock;
}
?>