Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Lib.System.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * LibSystem class
9  *
10  * This class provides methods for querying system informations
11  *
12  * @author Anakeen 2009
13  * @version $Id: Lib.System.php,v 1.4 2009/01/16 13:33:01 jerome Exp $
14  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
15  * @package FDL
16  * @subpackage
17  */
18 /**
19  */
20 include_once ("Lib.Common.php");
21 
22 class LibSystem
23 {
24 
25  static function getCommandPath($cmdname)
26  {
27  $path_env = getenv("PATH");
28  if ($path_env == false) {
29  return false;
30  }
31  foreach (explode(":", $path_env) as $path) {
32  if (file_exists("$path/$cmdname")) {
33  return "$path/$cmdname";
34  }
35  }
36  return false;
37  }
38 
39  static function getHostName()
40  {
41  return php_uname('n');
42  }
43 
44  static function getHostIPAddress($hostname = "")
45  {
46  if ($hostname == false) {
48  }
49  $ip = gethostbyname($hostname);
50  if ($ip == $hostname) {
51  return false;
52  }
53  return $ip;
54  }
55 
56  static function getServerName()
57  {
58  return getenv("SERVER_NAME");
59  }
60 
61  static function getServerAddr()
62  {
63  return getenv("SERVER_ADDR");
64  }
65 
66  static function runningInHttpd()
67  {
68  return LibSystem::getServerAddr();
69  }
70 
71  static function ssystem($args, $opt = null)
72  {
73  $pid = pcntl_fork();
74  if ($pid == - 1) {
75  return -1;
76  }
77  if ($pid != 0) {
78  $ret = pcntl_waitpid($pid, $status);
79  if ($ret == - 1) {
80  return -1;
81  }
82  return pcntl_wexitstatus($status);
83  }
84  $envs = array();
85  if ($opt && array_key_exists('envs', $opt) && is_array($opt['envs'])) {
86  $envs = $opt['envs'];
87  }
88  if ($opt && array_key_exists('closestdin', $opt) && $opt['closestdin'] === true) {
89  fclose(STDIN);
90  }
91  if ($opt && array_key_exists('closestdout', $opt) && $opt['closestdout'] === true) {
92  fclose(STDOUT);
93  }
94  if ($opt && array_key_exists('closestderr', $opt) && $opt['closestderr'] === true) {
95  fclose(STDERR);
96  }
97  $cmd = array_shift($args);
98  pcntl_exec($cmd, $args, $envs);
99  }
100 
101  static function getAbsolutePath($path)
102  {
103  if (is_link($path)) {
104  $path = readlink($path);
105  }
106  return realpath($path);
107  }
108 
109  static function tempnam($dir, $prefix)
110  {
111  if ($dir === null || $dir === false) {
112  $dir = getTmpDir();
113  }
114  return tempnam($dir, $prefix);
115  }
116 }
117 ?>
← centre documentaire © anakeen - published under CC License - Dynacase