function persist() { $file = tempnam(fbSystem::tempDirectory(), 'fbo'); if (!$file) { return false; } $data = serialize($this); if (!$data) { return false; } $fp = fopen($file, 'wb'); if (!$fp) { return false; } if (fwrite($fp, $data) != strlen($data)) { fclose($fp); @unlink($file); return false; } if (!fclose($fp)) { @unlink($file); return false; } return $file; }
require_once './_demo.php'; require_once FREEBEER_BASE . '/lib/System.php'; echo html_header_demo('fbSystem Class', FREEBEER_BASE . '/lib/System.php'); echo "\n<pre>\n"; echo 'platform=', fbSystem::platform(), "\n"; echo 'isCLI=', fbSystem::isCLI(), "\n"; echo 'isApache=', fbSystem::isApache(), "\n"; echo 'directorySeparator=', fbSystem::directorySeparator(), "\n"; $nl = fbSystem::lineSeparator(); echo 'lineSeparator='; for ($i = 0; $i < strlen($nl); ++$i) { printf("%d: %d ", $i + 1, ord($nl[$i])); } echo "\n"; echo 'pathSeparator=', fbSystem::pathSeparator(), "\n"; echo 'tempDirectory=', fbSystem::tempDirectory(), "\n"; echo 'extensionSuffix=', fbSystem::extensionSuffix(), "\n"; echo 'hostname=', fbSystem::hostname(), "\n"; echo 'username='******'include_path=', ini_get('include_path'), "\n"; fbSystem::appendIncludePath('appendme'); echo 'include_path=', ini_get('include_path'), "\n"; fbSystem::prependIncludePath('prependme'); echo 'include_path=', ini_get('include_path'), "\n"; echo 'loadExtension(\'standard\')=', fbSystem::loadExtension('standard'), "\n"; echo 'loadExtension(\'curl\')=', fbSystem::loadExtension('curl'), "\n"; echo 'loadExtension(\'failme\')=', fbSystem::loadExtension('failme'), "\n"; echo 'getLastError()=', fbSystem::getLastError(), "\n"; ?> </pre> <address>
function getEntropy() { /// \todo would implode('~', ...) be quicker? $entropy = microtime() . '~' . @getmypid() . '~' . @lcg_value() . '~' . @disk_free_space(fbSystem::tempDirectory()); if (function_exists('getrusage')) { $entropy .= '~' . serialize(@getrusage()); } if (function_exists('memory_get_usage')) { $entropy .= '~' . serialize(@memory_get_usage()); } if (function_exists('posix_times')) { $entropy .= '~' . serialize(@posix_times()); } global $_SERVER; // < 4.1.0 if (isset($_SERVER)) { $entropy .= '~' . serialize($_SERVER); } return $entropy; }
function _error_log($s) { static $file; if (!$file) { $file = fbSystem::tempDirectory() . '/phpdebug.log'; if (!is_file($file)) { @error_log('', 3, $file); $old_umask = @umask(0); @chmod($file, 0666); @umask($old_umask); } } @error_log($s, 3, $file); }
function test_tempDirectory() { $rv = fbSystem::tempDirectory(); $this->assertTrue(!empty($rv)); $this->assertTrue(@is_dir($rv), "Not a directory: '{$rv}'"); $this->assertTrue(@is_writeable($rv), "Not a writeable directory: '{$rv}'"); }
function _getTempName() { return tempnam(fbSystem::tempDirectory(), 'fbt'); }
function _init() { global $_SERVER; // < 4.1.0 if (fbSystem::isCLI()) { fbSystem::_initCLI(); return; } // IIS doesn't provide $_SERVER['SCRIPT_FILENAME'] if (!isset($_SERVER['SCRIPT_FILENAME'])) { if (isset($_SERVER['SCRIPT_NAME']) && $_SERVER['DOCUMENT_ROOT']) { $_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; } else { $_SERVER['SCRIPT_FILENAME'] = ''; } } // IIS doesn't provide $_SERVER['REQUEST_URI'] if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['PHP_SELF'])) { $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']; if (isset($_SERVER['PATH_INFO'])) { $_SERVER['REQUEST_URI'] .= $_SERVER['PATH_INFO']; } if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) { $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } } if (!isset($_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = ''; } $dir = trim(ini_get('upload_tmp_dir')); if (!$dir || !@is_dir($dir) || !is_writable($dir)) { @ini_set('upload_tmp_dir', fbSystem::tempDirectory()); } $dir = trim(ini_get('session.save_path')); if (!$dir || !@is_dir($dir) || !is_writable($dir)) { @ini_set('session.save_path', fbSystem::tempDirectory()); } }