|
1 <?php |
|
2 /***************************************************************************** |
|
3 * Copyright (C) 2014 |
|
4 * |
|
5 * Michiel Broek <mbroek at mbse dot eu> |
|
6 * |
|
7 * This file is part of ThermFerm |
|
8 * |
|
9 * This is free software; you can redistribute it and/or modify it |
|
10 * under the terms of the GNU General Public License as published by the |
|
11 * Free Software Foundation; either version 2, or (at your option) any |
|
12 * later version. |
|
13 * |
|
14 * ThermFerm is distributed in the hope that it will be useful, but |
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 * General Public License for more details. |
|
18 * |
|
19 * You should have received a copy of the GNU General Public License |
|
20 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
22 *****************************************************************************/ |
|
23 |
|
24 |
|
25 function open_socket() |
|
26 { |
|
27 $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
|
28 |
|
29 if (!($sock === false)) { |
|
30 if (socket_connect($sock, "localhost", 6554)) { |
|
31 socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0)); |
|
32 } else { |
|
33 socket_close($sock); |
|
34 } |
|
35 } |
|
36 return $sock; |
|
37 } |
|
38 |
|
39 |
|
40 |
|
41 function startsWith($haystack, $needle) |
|
42 { |
|
43 return !strncmp($haystack, $needle, strlen($needle)); |
|
44 } |
|
45 |
|
46 |