Http.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. /**
  3. * This file is part of workerman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Workerman\Protocols;
  15. use Workerman\Connection\TcpConnection;
  16. use Workerman\Worker;
  17. /**
  18. * http protocol
  19. */
  20. class Http
  21. {
  22. /**
  23. * The supported HTTP methods
  24. * @var array
  25. */
  26. public static $methods = array('GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS');
  27. /**
  28. * Check the integrity of the package.
  29. *
  30. * @param string $recv_buffer
  31. * @param TcpConnection $connection
  32. * @return int
  33. */
  34. public static function input($recv_buffer, TcpConnection $connection)
  35. {
  36. if (!strpos($recv_buffer, "\r\n\r\n")) {
  37. // Judge whether the package length exceeds the limit.
  38. if (strlen($recv_buffer) >= TcpConnection::$maxPackageSize) {
  39. $connection->close();
  40. return 0;
  41. }
  42. return 0;
  43. }
  44. list($header,) = explode("\r\n\r\n", $recv_buffer, 2);
  45. $method = substr($header, 0, strpos($header, ' '));
  46. if(in_array($method, static::$methods)) {
  47. return static::getRequestSize($header, $method);
  48. }else{
  49. $connection->send("HTTP/1.1 400 Bad Request\r\n\r\n", true);
  50. return 0;
  51. }
  52. }
  53. /**
  54. * Get whole size of the request
  55. * includes the request headers and request body.
  56. * @param string $header The request headers
  57. * @param string $method The request method
  58. * @return integer
  59. */
  60. protected static function getRequestSize($header, $method)
  61. {
  62. if($method === 'GET' || $method === 'OPTIONS' || $method === 'HEAD') {
  63. return strlen($header) + 4;
  64. }
  65. $match = array();
  66. if (preg_match("/\r\nContent-Length: ?(\d+)/i", $header, $match)) {
  67. $content_length = isset($match[1]) ? $match[1] : 0;
  68. return $content_length + strlen($header) + 4;
  69. }
  70. return 0;
  71. }
  72. /**
  73. * Parse $_POST、$_GET、$_COOKIE.
  74. *
  75. * @param string $recv_buffer
  76. * @param TcpConnection $connection
  77. * @return array
  78. */
  79. public static function decode($recv_buffer, TcpConnection $connection)
  80. {
  81. // Init.
  82. $_POST = $_GET = $_COOKIE = $_REQUEST = $_SESSION = $_FILES = array();
  83. $GLOBALS['HTTP_RAW_POST_DATA'] = '';
  84. // Clear cache.
  85. HttpCache::$header = array('Connection' => 'Connection: keep-alive');
  86. HttpCache::$instance = new HttpCache();
  87. // $_SERVER
  88. $_SERVER = array(
  89. 'QUERY_STRING' => '',
  90. 'REQUEST_METHOD' => '',
  91. 'REQUEST_URI' => '',
  92. 'SERVER_PROTOCOL' => '',
  93. 'SERVER_SOFTWARE' => 'workerman/'.Worker::VERSION,
  94. 'SERVER_NAME' => '',
  95. 'HTTP_HOST' => '',
  96. 'HTTP_USER_AGENT' => '',
  97. 'HTTP_ACCEPT' => '',
  98. 'HTTP_ACCEPT_LANGUAGE' => '',
  99. 'HTTP_ACCEPT_ENCODING' => '',
  100. 'HTTP_COOKIE' => '',
  101. 'HTTP_CONNECTION' => '',
  102. 'CONTENT_TYPE' => '',
  103. 'REMOTE_ADDR' => '',
  104. 'REMOTE_PORT' => '0',
  105. 'REQUEST_TIME' => time()
  106. );
  107. // Parse headers.
  108. list($http_header, $http_body) = explode("\r\n\r\n", $recv_buffer, 2);
  109. $header_data = explode("\r\n", $http_header);
  110. list($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PROTOCOL']) = explode(' ',
  111. $header_data[0]);
  112. $http_post_boundary = '';
  113. unset($header_data[0]);
  114. foreach ($header_data as $content) {
  115. // \r\n\r\n
  116. if (empty($content)) {
  117. continue;
  118. }
  119. list($key, $value) = explode(':', $content, 2);
  120. $key = str_replace('-', '_', strtoupper($key));
  121. $value = trim($value);
  122. $_SERVER['HTTP_' . $key] = $value;
  123. switch ($key) {
  124. // HTTP_HOST
  125. case 'HOST':
  126. $tmp = explode(':', $value);
  127. $_SERVER['SERVER_NAME'] = $tmp[0];
  128. if (isset($tmp[1])) {
  129. $_SERVER['SERVER_PORT'] = $tmp[1];
  130. }
  131. break;
  132. // cookie
  133. case 'COOKIE':
  134. parse_str(str_replace('; ', '&', $_SERVER['HTTP_COOKIE']), $_COOKIE);
  135. break;
  136. // content-type
  137. case 'CONTENT_TYPE':
  138. if (!preg_match('/boundary="?(\S+)"?/', $value, $match)) {
  139. if ($pos = strpos($value, ';')) {
  140. $_SERVER['CONTENT_TYPE'] = substr($value, 0, $pos);
  141. } else {
  142. $_SERVER['CONTENT_TYPE'] = $value;
  143. }
  144. } else {
  145. $_SERVER['CONTENT_TYPE'] = 'multipart/form-data';
  146. $http_post_boundary = '--' . $match[1];
  147. }
  148. break;
  149. case 'CONTENT_LENGTH':
  150. $_SERVER['CONTENT_LENGTH'] = $value;
  151. break;
  152. }
  153. }
  154. // Parse $_POST.
  155. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  156. if (isset($_SERVER['CONTENT_TYPE'])) {
  157. switch ($_SERVER['CONTENT_TYPE']) {
  158. case 'multipart/form-data':
  159. self::parseUploadFiles($http_body, $http_post_boundary);
  160. break;
  161. case 'application/json':
  162. $_POST = json_decode($http_body, true);
  163. break;
  164. case 'application/x-www-form-urlencoded':
  165. parse_str($http_body, $_POST);
  166. break;
  167. case 'application/json':
  168. $_POST = json_decode($http_body, true);
  169. break;
  170. }
  171. }
  172. }
  173. // Parse other HTTP action parameters
  174. if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != "POST") {
  175. $data = array();
  176. if ($_SERVER['CONTENT_TYPE'] === "application/x-www-form-urlencoded") {
  177. parse_str($http_body, $data);
  178. } elseif ($_SERVER['CONTENT_TYPE'] === "application/json") {
  179. $data = json_decode($http_body, true);
  180. }
  181. $_REQUEST = array_merge($_REQUEST, $data);
  182. }
  183. // HTTP_RAW_REQUEST_DATA HTTP_RAW_POST_DATA
  184. $GLOBALS['HTTP_RAW_REQUEST_DATA'] = $GLOBALS['HTTP_RAW_POST_DATA'] = $http_body;
  185. // QUERY_STRING
  186. $_SERVER['QUERY_STRING'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
  187. if ($_SERVER['QUERY_STRING']) {
  188. // $GET
  189. parse_str($_SERVER['QUERY_STRING'], $_GET);
  190. } else {
  191. $_SERVER['QUERY_STRING'] = '';
  192. }
  193. // REQUEST
  194. $_REQUEST = array_merge($_GET, $_POST, $_REQUEST);
  195. // REMOTE_ADDR REMOTE_PORT
  196. $_SERVER['REMOTE_ADDR'] = $connection->getRemoteIp();
  197. $_SERVER['REMOTE_PORT'] = $connection->getRemotePort();
  198. return array('get' => $_GET, 'post' => $_POST, 'cookie' => $_COOKIE, 'server' => $_SERVER, 'files' => $_FILES);
  199. }
  200. /**
  201. * Http encode.
  202. *
  203. * @param string $content
  204. * @param TcpConnection $connection
  205. * @return string
  206. */
  207. public static function encode($content, TcpConnection $connection)
  208. {
  209. // Default http-code.
  210. if (!isset(HttpCache::$header['Http-Code'])) {
  211. $header = "HTTP/1.1 200 OK\r\n";
  212. } else {
  213. $header = HttpCache::$header['Http-Code'] . "\r\n";
  214. unset(HttpCache::$header['Http-Code']);
  215. }
  216. // Content-Type
  217. if (!isset(HttpCache::$header['Content-Type'])) {
  218. $header .= "Content-Type: text/html;charset=utf-8\r\n";
  219. }
  220. // other headers
  221. foreach (HttpCache::$header as $key => $item) {
  222. if ('Set-Cookie' === $key && is_array($item)) {
  223. foreach ($item as $it) {
  224. $header .= $it . "\r\n";
  225. }
  226. } else {
  227. $header .= $item . "\r\n";
  228. }
  229. }
  230. // header
  231. $header .= "Server: workerman/" . Worker::VERSION . "\r\nContent-Length: " . strlen($content) . "\r\n\r\n";
  232. // save session
  233. self::sessionWriteClose();
  234. // the whole http package
  235. return $header . $content;
  236. }
  237. /**
  238. * 设置http头
  239. *
  240. * @return bool|void
  241. */
  242. public static function header($content, $replace = true, $http_response_code = 0)
  243. {
  244. if (PHP_SAPI != 'cli') {
  245. return $http_response_code ? header($content, $replace, $http_response_code) : header($content, $replace);
  246. }
  247. if (strpos($content, 'HTTP') === 0) {
  248. $key = 'Http-Code';
  249. } else {
  250. $key = strstr($content, ":", true);
  251. if (empty($key)) {
  252. return false;
  253. }
  254. }
  255. if ('location' === strtolower($key) && !$http_response_code) {
  256. return self::header($content, true, 302);
  257. }
  258. if (isset(HttpCache::$codes[$http_response_code])) {
  259. HttpCache::$header['Http-Code'] = "HTTP/1.1 $http_response_code " . HttpCache::$codes[$http_response_code];
  260. if ($key === 'Http-Code') {
  261. return true;
  262. }
  263. }
  264. if ($key === 'Set-Cookie') {
  265. HttpCache::$header[$key][] = $content;
  266. } else {
  267. HttpCache::$header[$key] = $content;
  268. }
  269. return true;
  270. }
  271. /**
  272. * Remove header.
  273. *
  274. * @param string $name
  275. * @return void
  276. */
  277. public static function headerRemove($name)
  278. {
  279. if (PHP_SAPI != 'cli') {
  280. header_remove($name);
  281. return;
  282. }
  283. unset(HttpCache::$header[$name]);
  284. }
  285. /**
  286. * Set cookie.
  287. *
  288. * @param string $name
  289. * @param string $value
  290. * @param integer $maxage
  291. * @param string $path
  292. * @param string $domain
  293. * @param bool $secure
  294. * @param bool $HTTPOnly
  295. * @return bool|void
  296. */
  297. public static function setcookie(
  298. $name,
  299. $value = '',
  300. $maxage = 0,
  301. $path = '',
  302. $domain = '',
  303. $secure = false,
  304. $HTTPOnly = false
  305. ) {
  306. if (PHP_SAPI != 'cli') {
  307. return setcookie($name, $value, $maxage, $path, $domain, $secure, $HTTPOnly);
  308. }
  309. return self::header(
  310. 'Set-Cookie: ' . $name . '=' . rawurlencode($value)
  311. . (empty($domain) ? '' : '; Domain=' . $domain)
  312. . (empty($maxage) ? '' : '; Max-Age=' . $maxage)
  313. . (empty($path) ? '' : '; Path=' . $path)
  314. . (!$secure ? '' : '; Secure')
  315. . (!$HTTPOnly ? '' : '; HttpOnly'), false);
  316. }
  317. /**
  318. * sessionCreateId
  319. *
  320. * @param string|prefix $prefix
  321. *
  322. * @return string
  323. */
  324. public static function sessionCreateId($prefix = null)
  325. {
  326. return session_create_id($prefix);
  327. }
  328. /**
  329. * sessionId
  330. *
  331. * @param string $id
  332. *
  333. * @return string|null
  334. */
  335. public static function sessionId($id = null)
  336. {
  337. if (PHP_SAPI != 'cli') {
  338. return $id ? session_id($id) : session_id();
  339. }
  340. if (static::sessionStarted() && HttpCache::$instance->sessionFile) {
  341. return str_replace('sess_', '', basename(HttpCache::$instance->sessionFile));
  342. }
  343. return '';
  344. }
  345. /**
  346. * sessionName
  347. *
  348. * @param string $name
  349. *
  350. * @return string
  351. */
  352. public static function sessionName($name = null)
  353. {
  354. if (PHP_SAPI != 'cli') {
  355. return $name ? session_name($name) : session_name();
  356. }
  357. $session_name = HttpCache::$sessionName;
  358. if ($name && ! static::sessionStarted()) {
  359. HttpCache::$sessionName = $name;
  360. }
  361. return $session_name;
  362. }
  363. /**
  364. * sessionSavePath
  365. *
  366. * @param string $path
  367. *
  368. * @return void
  369. */
  370. public static function sessionSavePath($path = null)
  371. {
  372. if (PHP_SAPI != 'cli') {
  373. return $path ? session_save_path($path) : session_save_path();
  374. }
  375. if ($path && is_dir($path) && is_writable($path) && !static::sessionStarted()) {
  376. HttpCache::$sessionPath = $path;
  377. }
  378. return HttpCache::$sessionPath;
  379. }
  380. /**
  381. * sessionStarted
  382. *
  383. * @return bool
  384. */
  385. public static function sessionStarted()
  386. {
  387. if (!HttpCache::$instance) return false;
  388. return HttpCache::$instance->sessionStarted;
  389. }
  390. /**
  391. * sessionStart
  392. *
  393. * @return bool
  394. */
  395. public static function sessionStart()
  396. {
  397. if (PHP_SAPI != 'cli') {
  398. return session_start();
  399. }
  400. self::tryGcSessions();
  401. if (HttpCache::$instance->sessionStarted) {
  402. echo "already sessionStarted\n";
  403. return true;
  404. }
  405. HttpCache::$instance->sessionStarted = true;
  406. // Generate a SID.
  407. if (!isset($_COOKIE[HttpCache::$sessionName]) || !is_file(HttpCache::$sessionPath . '/sess_' . $_COOKIE[HttpCache::$sessionName])) {
  408. // Create a unique session_id and the associated file name.
  409. while (true) {
  410. $session_id = static::sessionCreateId();
  411. if (!is_file($file_name = HttpCache::$sessionPath . '/sess_' . $session_id)) break;
  412. }
  413. HttpCache::$instance->sessionFile = $file_name;
  414. return self::setcookie(
  415. HttpCache::$sessionName
  416. , $session_id
  417. , ini_get('session.cookie_lifetime')
  418. , ini_get('session.cookie_path')
  419. , ini_get('session.cookie_domain')
  420. , ini_get('session.cookie_secure')
  421. , ini_get('session.cookie_httponly')
  422. );
  423. }
  424. if (!HttpCache::$instance->sessionFile) {
  425. HttpCache::$instance->sessionFile = HttpCache::$sessionPath . '/sess_' . $_COOKIE[HttpCache::$sessionName];
  426. }
  427. // Read session from session file.
  428. if (HttpCache::$instance->sessionFile) {
  429. $raw = file_get_contents(HttpCache::$instance->sessionFile);
  430. if ($raw) {
  431. $_SESSION = unserialize($raw);
  432. }
  433. }
  434. return true;
  435. }
  436. /**
  437. * Save session.
  438. *
  439. * @return bool
  440. */
  441. public static function sessionWriteClose()
  442. {
  443. if (PHP_SAPI != 'cli') {
  444. return session_write_close();
  445. }
  446. if (!empty(HttpCache::$instance->sessionStarted) && !empty($_SESSION)) {
  447. $session_str = serialize($_SESSION);
  448. if ($session_str && HttpCache::$instance->sessionFile) {
  449. return file_put_contents(HttpCache::$instance->sessionFile, $session_str);
  450. }
  451. }
  452. return empty($_SESSION);
  453. }
  454. /**
  455. * End, like call exit in php-fpm.
  456. *
  457. * @param string $msg
  458. * @throws \Exception
  459. */
  460. public static function end($msg = '')
  461. {
  462. if (PHP_SAPI != 'cli') {
  463. exit($msg);
  464. }
  465. if ($msg) {
  466. echo $msg;
  467. }
  468. throw new \Exception('jump_exit');
  469. }
  470. /**
  471. * Get mime types.
  472. *
  473. * @return string
  474. */
  475. public static function getMimeTypesFile()
  476. {
  477. return __DIR__ . '/Http/mime.types';
  478. }
  479. /**
  480. * Parse $_FILES.
  481. *
  482. * @param string $http_body
  483. * @param string $http_post_boundary
  484. * @return void
  485. */
  486. protected static function parseUploadFiles($http_body, $http_post_boundary)
  487. {
  488. $http_body = substr($http_body, 0, strlen($http_body) - (strlen($http_post_boundary) + 4));
  489. $boundary_data_array = explode($http_post_boundary . "\r\n", $http_body);
  490. if ($boundary_data_array[0] === '') {
  491. unset($boundary_data_array[0]);
  492. }
  493. $key = -1;
  494. foreach ($boundary_data_array as $boundary_data_buffer) {
  495. list($boundary_header_buffer, $boundary_value) = explode("\r\n\r\n", $boundary_data_buffer, 2);
  496. // Remove \r\n from the end of buffer.
  497. $boundary_value = substr($boundary_value, 0, -2);
  498. $key ++;
  499. foreach (explode("\r\n", $boundary_header_buffer) as $item) {
  500. list($header_key, $header_value) = explode(": ", $item);
  501. $header_key = strtolower($header_key);
  502. switch ($header_key) {
  503. case "content-disposition":
  504. // Is file data.
  505. if (preg_match('/name="(.*?)"; filename="(.*?)"$/', $header_value, $match)) {
  506. // Parse $_FILES.
  507. $_FILES[$key] = array(
  508. 'name' => $match[1],
  509. 'file_name' => $match[2],
  510. 'file_data' => $boundary_value,
  511. 'file_size' => strlen($boundary_value),
  512. );
  513. continue;
  514. } // Is post field.
  515. else {
  516. // Parse $_POST.
  517. if (preg_match('/name="(.*?)"$/', $header_value, $match)) {
  518. $_POST[$match[1]] = $boundary_value;
  519. }
  520. }
  521. break;
  522. case "content-type":
  523. // add file_type
  524. $_FILES[$key]['file_type'] = trim($header_value);
  525. break;
  526. }
  527. }
  528. }
  529. }
  530. /**
  531. * Try GC sessions.
  532. *
  533. * @return void
  534. */
  535. public static function tryGcSessions()
  536. {
  537. if (HttpCache::$sessionGcProbability <= 0 ||
  538. HttpCache::$sessionGcDivisor <= 0 ||
  539. rand(1, HttpCache::$sessionGcDivisor) > HttpCache::$sessionGcProbability) {
  540. return;
  541. }
  542. $time_now = time();
  543. foreach(glob(HttpCache::$sessionPath.'/ses*') as $file) {
  544. if(is_file($file) && $time_now - filemtime($file) > HttpCache::$sessionGcMaxLifeTime) {
  545. unlink($file);
  546. }
  547. }
  548. }
  549. }
  550. /**
  551. * Http cache for the current http response.
  552. */
  553. class HttpCache
  554. {
  555. public static $codes = array(
  556. 100 => 'Continue',
  557. 101 => 'Switching Protocols',
  558. 200 => 'OK',
  559. 201 => 'Created',
  560. 202 => 'Accepted',
  561. 203 => 'Non-Authoritative Information',
  562. 204 => 'No Content',
  563. 205 => 'Reset Content',
  564. 206 => 'Partial Content',
  565. 300 => 'Multiple Choices',
  566. 301 => 'Moved Permanently',
  567. 302 => 'Found',
  568. 303 => 'See Other',
  569. 304 => 'Not Modified',
  570. 305 => 'Use Proxy',
  571. 306 => '(Unused)',
  572. 307 => 'Temporary Redirect',
  573. 400 => 'Bad Request',
  574. 401 => 'Unauthorized',
  575. 402 => 'Payment Required',
  576. 403 => 'Forbidden',
  577. 404 => 'Not Found',
  578. 405 => 'Method Not Allowed',
  579. 406 => 'Not Acceptable',
  580. 407 => 'Proxy Authentication Required',
  581. 408 => 'Request Timeout',
  582. 409 => 'Conflict',
  583. 410 => 'Gone',
  584. 411 => 'Length Required',
  585. 412 => 'Precondition Failed',
  586. 413 => 'Request Entity Too Large',
  587. 414 => 'Request-URI Too Long',
  588. 415 => 'Unsupported Media Type',
  589. 416 => 'Requested Range Not Satisfiable',
  590. 417 => 'Expectation Failed',
  591. 422 => 'Unprocessable Entity',
  592. 423 => 'Locked',
  593. 500 => 'Internal Server Error',
  594. 501 => 'Not Implemented',
  595. 502 => 'Bad Gateway',
  596. 503 => 'Service Unavailable',
  597. 504 => 'Gateway Timeout',
  598. 505 => 'HTTP Version Not Supported',
  599. );
  600. /**
  601. * @var HttpCache
  602. */
  603. public static $instance = null;
  604. public static $header = array();
  605. public static $sessionPath = '';
  606. public static $sessionName = '';
  607. public static $sessionGcProbability = 1;
  608. public static $sessionGcDivisor = 1000;
  609. public static $sessionGcMaxLifeTime = 1440;
  610. public $sessionStarted = false;
  611. public $sessionFile = '';
  612. public static function init()
  613. {
  614. if (!self::$sessionName) {
  615. self::$sessionName = ini_get('session.name');
  616. }
  617. if (!self::$sessionPath) {
  618. self::$sessionPath = @session_save_path();
  619. }
  620. if (!self::$sessionPath || strpos(self::$sessionPath, 'tcp://') === 0) {
  621. self::$sessionPath = sys_get_temp_dir();
  622. }
  623. if ($gc_probability = ini_get('session.gc_probability')) {
  624. self::$sessionGcProbability = $gc_probability;
  625. }
  626. if ($gc_divisor = ini_get('session.gc_divisor')) {
  627. self::$sessionGcDivisor = $gc_divisor;
  628. }
  629. if ($gc_max_life_time = ini_get('session.gc_maxlifetime')) {
  630. self::$sessionGcMaxLifeTime = $gc_max_life_time;
  631. }
  632. }
  633. }
  634. HttpCache::init();