Core  3.2
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  * @package FDL
5 */
6 /**
7  * LibSystem class
8  *
9  * This class provides methods for querying system informations
10  *
11  * @author Anakeen
12  * @version $Id: Lib.System.php,v 1.4 2009/01/16 13:33:01 jerome Exp $
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 include_once ("Lib.Common.php");
19 
20 class LibSystem
21 {
22 
23  static function getCommandPath($cmdname)
24  {
25  $path_env = getenv("PATH");
26  if ($path_env == false) {
27  return false;
28  }
29  foreach (explode(":", $path_env) as $path) {
30  if (file_exists("$path/$cmdname")) {
31  return "$path/$cmdname";
32  }
33  }
34  return false;
35  }
36 
37  static function getHostName()
38  {
39  return php_uname('n');
40  }
41 
42  static function getHostIPAddress($hostname = "")
43  {
44  if ($hostname == false) {
45  $hostname = LibSystem::getHostName();
46  }
47  $ip = gethostbyname($hostname);
48  if ($ip == $hostname) {
49  return false;
50  }
51  return $ip;
52  }
53 
54  static function getServerName()
55  {
56  return getenv("SERVER_NAME");
57  }
58 
59  static function getServerAddr()
60  {
61  return getenv("SERVER_ADDR");
62  }
63 
64  static function runningInHttpd()
65  {
66  return LibSystem::getServerAddr();
67  }
68 
69  static function ssystem($args, $opt = null)
70  {
71  $pid = pcntl_fork();
72  if ($pid == - 1) {
73  return -1;
74  }
75  if ($pid != 0) {
76  $ret = pcntl_waitpid($pid, $status);
77  if ($ret == - 1) {
78  return -1;
79  }
80  return pcntl_wexitstatus($status);
81  }
82  $envs = array();
83  if ($opt && array_key_exists('envs', $opt) && is_array($opt['envs'])) {
84  $envs = $opt['envs'];
85  }
86  if ($opt && array_key_exists('closestdin', $opt) && $opt['closestdin'] === true) {
87  fclose(STDIN);
88  }
89  if ($opt && array_key_exists('closestdout', $opt) && $opt['closestdout'] === true) {
90  fclose(STDOUT);
91  }
92  if ($opt && array_key_exists('closestderr', $opt) && $opt['closestderr'] === true) {
93  fclose(STDERR);
94  }
95  $cmd = array_shift($args);
96  pcntl_exec($cmd, $args, $envs);
97  return 0;
98  }
99 
100  static function getAbsolutePath($path)
101  {
102  if (is_link($path)) {
103  $path = readlink($path);
104  }
105  return realpath($path);
106  }
107 
108  static function tempnam($dir, $prefix)
109  {
110  if ($dir === null || $dir === false) {
111  $dir = getTmpDir();
112  }
113  return tempnam($dir, $prefix);
114  }
115  /**
116  * force new index
117  */
118  static function reloadLocaleCache()
119  {
120  exec(sprintf("%s/whattext 2>&1", escapeshellarg(DEFAULT_PUBDIR)) , $output, $ret);
121  if ($ret) {
122  error_log(implode(",", $output));
123  }
124  }
125 }
126 ?>
static ssystem($args, $opt=null)
Definition: Lib.System.php:69
static getAbsolutePath($path)
Definition: Lib.System.php:100
if(substr($wsh, 0, 1)!= '/') $args
$status
Definition: index.php:30
static getServerName()
Definition: Lib.System.php:54
static reloadLocaleCache()
Definition: Lib.System.php:118
static runningInHttpd()
Definition: Lib.System.php:64
$ret
static getHostName()
Definition: Lib.System.php:37
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
foreach($argv as $arg) $cmd
static getCommandPath($cmdname)
Definition: Lib.System.php:23
$path
Definition: dav.php:39
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
static getHostIPAddress($hostname="")
Definition: Lib.System.php:42
static tempnam($dir, $prefix)
Definition: Lib.System.php:108
$dir
Definition: resizeimg.php:144
static getServerAddr()
Definition: Lib.System.php:59
← centre documentaire © anakeen