| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\InfoException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Sets the process title visible in tools such as top and |
| 9 |
* ps. This function is available only in |
| 10 |
* CLI mode. |
| 11 |
* |
| 12 |
* @param string $title The new title. |
| 13 |
* @throws InfoException |
| 14 |
* |
| 15 |
*/ |
| 16 |
function cli_set_process_title(string $title): void |
| 17 |
{ |
| 18 |
error_clear_last(); |
| 19 |
$result = \cli_set_process_title($title); |
| 20 |
if ($result === false) { |
| 21 |
throw InfoException::createFromPhpError(); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Loads the PHP extension given by the parameter |
| 28 |
* library. |
| 29 |
* |
| 30 |
* Use extension_loaded to test whether a given |
| 31 |
* extension is already available or not. This works on both built-in |
| 32 |
* extensions and dynamically loaded ones (either through php.ini or |
| 33 |
* dl). |
| 34 |
* |
| 35 |
* @param string $library This parameter is only the filename of the |
| 36 |
* extension to load which also depends on your platform. For example, |
| 37 |
* the sockets extension (if compiled |
| 38 |
* as a shared module, not the default!) would be called |
| 39 |
* sockets.so on Unix platforms whereas it is called |
| 40 |
* php_sockets.dll on the Windows platform. |
| 41 |
* |
| 42 |
* The directory where the extension is loaded from depends on your |
| 43 |
* platform: |
| 44 |
* |
| 45 |
* Windows - If not explicitly set in the php.ini, the extension is |
| 46 |
* loaded from C:\php5\ by default. |
| 47 |
* |
| 48 |
* Unix - If not explicitly set in the php.ini, the default extension |
| 49 |
* directory depends on |
| 50 |
* |
| 51 |
* |
| 52 |
* |
| 53 |
* whether PHP has been built with --enable-debug |
| 54 |
* or not |
| 55 |
* |
| 56 |
* |
| 57 |
* |
| 58 |
* |
| 59 |
* whether PHP has been built with (experimental) ZTS (Zend Thread Safety) |
| 60 |
* support or not |
| 61 |
* |
| 62 |
* |
| 63 |
* |
| 64 |
* |
| 65 |
* the current internal ZEND_MODULE_API_NO (Zend |
| 66 |
* internal module API number, which is basically the date on which a |
| 67 |
* major module API change happened, e.g. 20010901) |
| 68 |
* |
| 69 |
* |
| 70 |
* |
| 71 |
* Taking into account the above, the directory then defaults to |
| 72 |
* <install-dir>/lib/php/extensions/ <debug-or-not>-<zts-or-not>-ZEND_MODULE_API_NO, |
| 73 |
* e.g. |
| 74 |
* /usr/local/php/lib/php/extensions/debug-non-zts-20010901 |
| 75 |
* or |
| 76 |
* /usr/local/php/lib/php/extensions/no-debug-zts-20010901. |
| 77 |
* @throws InfoException |
| 78 |
* |
| 79 |
*/ |
| 80 |
function dl(string $library): void |
| 81 |
{ |
| 82 |
error_clear_last(); |
| 83 |
$result = \dl($library); |
| 84 |
if ($result === false) { |
| 85 |
throw InfoException::createFromPhpError(); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
/** |
| 91 |
* Gets the time of the last modification of the main script of execution. |
| 92 |
* |
| 93 |
* If you're interested in getting the last modification time |
| 94 |
* of a different file, consider using filemtime. |
| 95 |
* |
| 96 |
* @return int Returns the time of the last modification of the current |
| 97 |
* page. The value returned is a Unix timestamp, suitable for |
| 98 |
* feeding to date. |
| 99 |
* @throws InfoException |
| 100 |
* |
| 101 |
*/ |
| 102 |
function getlastmod(): int |
| 103 |
{ |
| 104 |
error_clear_last(); |
| 105 |
$result = \getlastmod(); |
| 106 |
if ($result === false) { |
| 107 |
throw InfoException::createFromPhpError(); |
| 108 |
} |
| 109 |
return $result; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
/** |
| 114 |
* |
| 115 |
* |
| 116 |
* @return int Returns the group ID of the current script. |
| 117 |
* @throws InfoException |
| 118 |
* |
| 119 |
*/ |
| 120 |
function getmygid(): int |
| 121 |
{ |
| 122 |
error_clear_last(); |
| 123 |
$result = \getmygid(); |
| 124 |
if ($result === false) { |
| 125 |
throw InfoException::createFromPhpError(); |
| 126 |
} |
| 127 |
return $result; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
/** |
| 132 |
* Gets the inode of the current script. |
| 133 |
* |
| 134 |
* @return int Returns the current script's inode as an integer. |
| 135 |
* @throws InfoException |
| 136 |
* |
| 137 |
*/ |
| 138 |
function getmyinode(): int |
| 139 |
{ |
| 140 |
error_clear_last(); |
| 141 |
$result = \getmyinode(); |
| 142 |
if ($result === false) { |
| 143 |
throw InfoException::createFromPhpError(); |
| 144 |
} |
| 145 |
return $result; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
/** |
| 150 |
* Gets the current PHP process ID. |
| 151 |
* |
| 152 |
* @return int Returns the current PHP process ID. |
| 153 |
* @throws InfoException |
| 154 |
* |
| 155 |
*/ |
| 156 |
function getmypid(): int |
| 157 |
{ |
| 158 |
error_clear_last(); |
| 159 |
$result = \getmypid(); |
| 160 |
if ($result === false) { |
| 161 |
throw InfoException::createFromPhpError(); |
| 162 |
} |
| 163 |
return $result; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
/** |
| 168 |
* |
| 169 |
* |
| 170 |
* @return int Returns the user ID of the current script. |
| 171 |
* @throws InfoException |
| 172 |
* |
| 173 |
*/ |
| 174 |
function getmyuid(): int |
| 175 |
{ |
| 176 |
error_clear_last(); |
| 177 |
$result = \getmyuid(); |
| 178 |
if ($result === false) { |
| 179 |
throw InfoException::createFromPhpError(); |
| 180 |
} |
| 181 |
return $result; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
/** |
| 186 |
* Parses options passed to the script. |
| 187 |
* |
| 188 |
* @param string $options |
| 189 |
* @param array|null $longopts |
| 190 |
* @param int|null $optind |
| 191 |
* |
| 192 |
* @return array|array|array This function will return an array of option / argument pairs. |
| 193 |
* @throws InfoException |
| 194 |
* |
| 195 |
*/ |
| 196 |
function getopt(string $options, ?array $longopts = null, ?int &$optind = null): array |
| 197 |
{ |
| 198 |
error_clear_last(); |
| 199 |
if ($optind !== null) { |
| 200 |
$result = \getopt($options, $longopts, $optind); |
| 201 |
} elseif ($longopts !== null) { |
| 202 |
$result = \getopt($options, $longopts); |
| 203 |
} else { |
| 204 |
$result = \getopt($options); |
| 205 |
} |
| 206 |
if ($result === false) { |
| 207 |
throw InfoException::createFromPhpError(); |
| 208 |
} |
| 209 |
return $result; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
/** |
| 214 |
* Returns the value of the configuration option on success. |
| 215 |
* |
| 216 |
* @param string $varname The configuration option name. |
| 217 |
* @return string Returns the value of the configuration option as a string on success, or an |
| 218 |
* empty string for null values. Returns FALSE if the |
| 219 |
* configuration option doesn't exist. |
| 220 |
* @throws InfoException |
| 221 |
* |
| 222 |
*/ |
| 223 |
function ini_get(string $varname): string |
| 224 |
{ |
| 225 |
error_clear_last(); |
| 226 |
$result = \ini_get($varname); |
| 227 |
if ($result === false) { |
| 228 |
throw InfoException::createFromPhpError(); |
| 229 |
} |
| 230 |
return $result; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
/** |
| 235 |
* Sets the value of the given configuration option. The configuration option |
| 236 |
* will keep this new value during the script's execution, and will be restored |
| 237 |
* at the script's ending. |
| 238 |
* |
| 239 |
* @param string $varname Not all the available options can be changed using |
| 240 |
* ini_set. There is a list of all available options |
| 241 |
* in the appendix. |
| 242 |
* @param string|int|float|bool $newvalue The new value for the option. |
| 243 |
* @return string Returns the old value on success, FALSE on failure. |
| 244 |
* @throws InfoException |
| 245 |
* |
| 246 |
*/ |
| 247 |
function ini_set(string $varname, $newvalue): string |
| 248 |
{ |
| 249 |
error_clear_last(); |
| 250 |
$result = \ini_set($varname, $newvalue); |
| 251 |
if ($result === false) { |
| 252 |
throw InfoException::createFromPhpError(); |
| 253 |
} |
| 254 |
return $result; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
/** |
| 259 |
* This function prints out the credits listing the PHP developers, |
| 260 |
* modules, etc. It generates the appropriate HTML codes to insert |
| 261 |
* the information in a page. |
| 262 |
* |
| 263 |
* @param int $flag To generate a custom credits page, you may want to use the |
| 264 |
* flag parameter. |
| 265 |
* |
| 266 |
* |
| 267 |
* Pre-defined phpcredits flags |
| 268 |
* |
| 269 |
* |
| 270 |
* |
| 271 |
* name |
| 272 |
* description |
| 273 |
* |
| 274 |
* |
| 275 |
* |
| 276 |
* |
| 277 |
* CREDITS_ALL |
| 278 |
* |
| 279 |
* All the credits, equivalent to using: CREDITS_DOCS + |
| 280 |
* CREDITS_GENERAL + CREDITS_GROUP + |
| 281 |
* CREDITS_MODULES + CREDITS_FULLPAGE. |
| 282 |
* It generates a complete stand-alone HTML page with the appropriate tags. |
| 283 |
* |
| 284 |
* |
| 285 |
* |
| 286 |
* CREDITS_DOCS |
| 287 |
* The credits for the documentation team |
| 288 |
* |
| 289 |
* |
| 290 |
* CREDITS_FULLPAGE |
| 291 |
* |
| 292 |
* Usually used in combination with the other flags. Indicates |
| 293 |
* that a complete stand-alone HTML page needs to be |
| 294 |
* printed including the information indicated by the other |
| 295 |
* flags. |
| 296 |
* |
| 297 |
* |
| 298 |
* |
| 299 |
* CREDITS_GENERAL |
| 300 |
* |
| 301 |
* General credits: Language design and concept, PHP authors |
| 302 |
* and SAPI module. |
| 303 |
* |
| 304 |
* |
| 305 |
* |
| 306 |
* CREDITS_GROUP |
| 307 |
* A list of the core developers |
| 308 |
* |
| 309 |
* |
| 310 |
* CREDITS_MODULES |
| 311 |
* |
| 312 |
* A list of the extension modules for PHP, and their authors |
| 313 |
* |
| 314 |
* |
| 315 |
* |
| 316 |
* CREDITS_SAPI |
| 317 |
* |
| 318 |
* A list of the server API modules for PHP, and their authors |
| 319 |
* |
| 320 |
* |
| 321 |
* |
| 322 |
* |
| 323 |
* |
| 324 |
* @throws InfoException |
| 325 |
* |
| 326 |
*/ |
| 327 |
function phpcredits(int $flag = CREDITS_ALL): void |
| 328 |
{ |
| 329 |
error_clear_last(); |
| 330 |
$result = \phpcredits($flag); |
| 331 |
if ($result === false) { |
| 332 |
throw InfoException::createFromPhpError(); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
/** |
| 338 |
* Outputs a large amount of information about the current state of PHP. |
| 339 |
* This includes information about PHP compilation options and extensions, |
| 340 |
* the PHP version, server information and environment (if compiled as a |
| 341 |
* module), the PHP environment, OS version information, paths, master and |
| 342 |
* local values of configuration options, HTTP headers, and the PHP License. |
| 343 |
* |
| 344 |
* Because every system is setup differently, phpinfo is |
| 345 |
* commonly used to check configuration settings and for available |
| 346 |
* predefined variables |
| 347 |
* on a given system. |
| 348 |
* |
| 349 |
* phpinfo is also a valuable debugging tool as it |
| 350 |
* contains all EGPCS (Environment, GET, POST, Cookie, Server) data. |
| 351 |
* |
| 352 |
* @param int $what The output may be customized by passing one or more of the |
| 353 |
* following constants bitwise values summed |
| 354 |
* together in the optional what parameter. |
| 355 |
* One can also combine the respective constants or bitwise values |
| 356 |
* together with the bitwise or operator. |
| 357 |
* |
| 358 |
* |
| 359 |
* phpinfo options |
| 360 |
* |
| 361 |
* |
| 362 |
* |
| 363 |
* Name (constant) |
| 364 |
* Value |
| 365 |
* Description |
| 366 |
* |
| 367 |
* |
| 368 |
* |
| 369 |
* |
| 370 |
* INFO_GENERAL |
| 371 |
* 1 |
| 372 |
* |
| 373 |
* The configuration line, php.ini location, build date, Web |
| 374 |
* Server, System and more. |
| 375 |
* |
| 376 |
* |
| 377 |
* |
| 378 |
* INFO_CREDITS |
| 379 |
* 2 |
| 380 |
* |
| 381 |
* PHP Credits. See also phpcredits. |
| 382 |
* |
| 383 |
* |
| 384 |
* |
| 385 |
* INFO_CONFIGURATION |
| 386 |
* 4 |
| 387 |
* |
| 388 |
* Current Local and Master values for PHP directives. See |
| 389 |
* also ini_get. |
| 390 |
* |
| 391 |
* |
| 392 |
* |
| 393 |
* INFO_MODULES |
| 394 |
* 8 |
| 395 |
* |
| 396 |
* Loaded modules and their respective settings. See also |
| 397 |
* get_loaded_extensions. |
| 398 |
* |
| 399 |
* |
| 400 |
* |
| 401 |
* INFO_ENVIRONMENT |
| 402 |
* 16 |
| 403 |
* |
| 404 |
* Environment Variable information that's also available in |
| 405 |
* $_ENV. |
| 406 |
* |
| 407 |
* |
| 408 |
* |
| 409 |
* INFO_VARIABLES |
| 410 |
* 32 |
| 411 |
* |
| 412 |
* Shows all |
| 413 |
* predefined variables from EGPCS (Environment, GET, |
| 414 |
* POST, Cookie, Server). |
| 415 |
* |
| 416 |
* |
| 417 |
* |
| 418 |
* INFO_LICENSE |
| 419 |
* 64 |
| 420 |
* |
| 421 |
* PHP License information. See also the license FAQ. |
| 422 |
* |
| 423 |
* |
| 424 |
* |
| 425 |
* INFO_ALL |
| 426 |
* -1 |
| 427 |
* |
| 428 |
* Shows all of the above. |
| 429 |
* |
| 430 |
* |
| 431 |
* |
| 432 |
* |
| 433 |
* |
| 434 |
* @throws InfoException |
| 435 |
* |
| 436 |
*/ |
| 437 |
function phpinfo(int $what = INFO_ALL): void |
| 438 |
{ |
| 439 |
error_clear_last(); |
| 440 |
$result = \phpinfo($what); |
| 441 |
if ($result === false) { |
| 442 |
throw InfoException::createFromPhpError(); |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
/** |
| 448 |
* Adds setting to the server environment. The |
| 449 |
* environment variable will only exist for the duration of the current |
| 450 |
* request. At the end of the request the environment is restored to its |
| 451 |
* original state. |
| 452 |
* |
| 453 |
* @param string $setting The setting, like "FOO=BAR" |
| 454 |
* @throws InfoException |
| 455 |
* |
| 456 |
*/ |
| 457 |
function putenv(string $setting): void |
| 458 |
{ |
| 459 |
error_clear_last(); |
| 460 |
$result = \putenv($setting); |
| 461 |
if ($result === false) { |
| 462 |
throw InfoException::createFromPhpError(); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
/** |
| 468 |
* Sets the include_path |
| 469 |
* configuration option for the duration of the script. |
| 470 |
* |
| 471 |
* @param string $new_include_path The new value for the include_path |
| 472 |
* @return string Returns the old include_path on |
| 473 |
* success. |
| 474 |
* @throws InfoException |
| 475 |
* |
| 476 |
*/ |
| 477 |
function set_include_path(string $new_include_path): string |
| 478 |
{ |
| 479 |
error_clear_last(); |
| 480 |
$result = \set_include_path($new_include_path); |
| 481 |
if ($result === false) { |
| 482 |
throw InfoException::createFromPhpError(); |
| 483 |
} |
| 484 |
return $result; |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
/** |
| 489 |
* Set the number of seconds a script is allowed to run. If this is reached, |
| 490 |
* the script returns a fatal error. The default limit is 30 seconds or, if |
| 491 |
* it exists, the max_execution_time value defined in the |
| 492 |
* php.ini. |
| 493 |
* |
| 494 |
* When called, set_time_limit restarts the timeout |
| 495 |
* counter from zero. In other words, if the timeout is the default 30 |
| 496 |
* seconds, and 25 seconds into script execution a call such as |
| 497 |
* set_time_limit(20) is made, the script will run for a |
| 498 |
* total of 45 seconds before timing out. |
| 499 |
* |
| 500 |
* @param int $seconds The maximum execution time, in seconds. If set to zero, no time limit |
| 501 |
* is imposed. |
| 502 |
* @throws InfoException |
| 503 |
* |
| 504 |
*/ |
| 505 |
function set_time_limit(int $seconds): void |
| 506 |
{ |
| 507 |
error_clear_last(); |
| 508 |
$result = \set_time_limit($seconds); |
| 509 |
if ($result === false) { |
| 510 |
throw InfoException::createFromPhpError(); |
| 511 |
} |
| 512 |
} |
| 513 |
|