08c10-2.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 34 行

PHP
34
字号
<?php// We are going to be outputting a graphic so start with the proper headersheader('Content-type: image/jpeg');// Register a shutdown function, so if we fail, the basic file is returnedfunction shutdown() {    // If we never managed to read the file:    if (!(isset($GLOBALS['data'])) || !($GLOBALS['data'])) {        // Output the cached file, ensure a full absolute path:        readfile(dirname(__FILE__) . '/hubble_news.cache');    }}register_shutdown_function('shutdown');// Set a quick timeout value so if we don't get it quickly it uses the cacheset_time_limit(5);// Try to read in the remote file:if ($data = @file_get_contents(        'http://hubblesite.org/news/latest_big.php')) {    // Quickly reset the timer so we don't timeout while writing the cache    set_time_limit(60);    // We got the file, so echo out the contents    echo $data;    // Now we need to save this to the cache file as well.    // Give file_put_contents the LOCK_EX flag which makes it    // attempt to get an exclusive lock before writing to the file.    ignore_user_abort(true);    file_put_contents(dirname(__FILE__) . '/hubble_news.cache',         $data, LOCK_EX);}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?