• 首页|
  • Community
    Articles Topics Q&A
    Learn
    Course Programming Dictionary
    Tools Library
    Development tools Website Source Code PHP Libraries JS special effects Website Materials Extension plug-ins
    AI Tools
    Leisure
    Game Download Game Tutorials
    search
    English
    简体中文 English 繁体中文 日本語 한국어 Melayu Français Deutsch
    Login
    singup
    Home Backend Development PHP Tutorial 用PHP实现WEB动态网页静态化_PHP

    用PHP实现WEB动态网页静态化_PHP

    WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
    WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
    Jun 01, 2016 pm 12:34 PM
    dynamic accomplish Web page static page

    在最近几年,万维网(也称环球信息网,即WWW)不断改变信息处理技术的面貌。WEB已经快速地成为一种有效的媒介,并适合人们和商业沟通和协作。几乎所有的信息技术领域都普遍受到WEB的影响。Web访问带来更多用户和更多数据,这意味着给服务器和数据库更多压力和最终用户得到越来越慢的响应速度。与不断靠增加CPU,磁盘驱动器及内存来跟上这种增长的需求相比, WEB动态网页面静态化应该是一个更实用,更经济的选择。

    用PHP实现WEB动态网页静态化的具体实现函数如function gen_static_file()所示


    function gen_static_file($program, $filename)
    {
    $program 1= "/usr/local/apache/htdocs/php/" . $program;
    $filename1 = "/usr/local/apache/htdocs/ static_html/" . $filename;
    $cmd_str = "/usr/local/php4/bin/php " . $program1 . " } " . $filename1 . " ";
    system($cmd_str);
    echo $filename . " generated.〈br〉";
    }


    这个函数是实现静态化的关键,即PHP动态页面程序不是被送到浏览器中,而是输入到名为$filename的文件中去(如图2)。两个参数中$program是PHP动态页面程序,$filename是生成的静态页面的名字(可根据需要自己制定命名规则,这一点很重要,见下文),/usr/local/php4/bin/php是PHP中具有把程序输入文件功能的部分,System是PHP中执行外部命令的函数。我们还可以看出所有生成动态页面的php程序需放在/php/目录下,所有新产生的静态页面则会出现在/static_html/目录下(这些路径可以根据具体需要设置)。

    下面让我们举个具体例子,看一下college_static.php的静态页面是怎样生成的。


    function gen_college_static ()
    {
    for ($i = 0; $i 〈= 32; $i++〉
    {
    putenv("province_id=" . $i); //*.php文件从数据库取数据时要用到。
    $filename = " college_static". $i . ".html";
    gen_static_file("college_static.php", $filename);
    }


    从这个函数我们可以看到通过调用函数gen_static_file(), college_static.php经过静态化,变成了33个静态页面college.static0.html~college.static33.html,其中$filename会随着$I的变化而变化。当然也可以从数据库中直接取值,来控制生成的静态页面的个数和名字,其他程序对生成的静态页面的调用应和静态页面的命名规则一致。

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Show More

    Hot Article

    How to fix KB5055523 fails to install in Windows 11?
    4 weeks ago By DDD
    How to fix KB5055518 fails to install in Windows 10?
    4 weeks ago By DDD
    Roblox: Grow A Garden - Complete Mutation Guide
    3 weeks ago By DDD
    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    How to fix KB5055612 fails to install in Windows 10?
    3 weeks ago By DDD
    Show More

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Show More

    Hot Topics

    Java Tutorial
    1664
    14
    CakePHP Tutorial
    1422
    52
    Laravel Tutorial
    1316
    25
    PHP Tutorial
    1267
    29
    C# Tutorial
    1239
    24
    Show More
    Related knowledge
    How to send web pages to desktop as shortcut in Edge browser? How to send web pages to desktop as shortcut in Edge browser? Mar 14, 2024 pm 05:22 PM

    How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

    Convert VirtualBox fixed disk to dynamic disk and vice versa Convert VirtualBox fixed disk to dynamic disk and vice versa Mar 25, 2024 am 09:36 AM

    When creating a virtual machine, you will be asked to select a disk type, you can select fixed disk or dynamic disk. What if you choose fixed disks and later realize you need dynamic disks, or vice versa? Good! You can convert one to the other. In this post, we will see how to convert VirtualBox fixed disk to dynamic disk and vice versa. A dynamic disk is a virtual hard disk that initially has a small size and grows in size as you store data in the virtual machine. Dynamic disks are very efficient at saving storage space because they only take up as much host storage space as needed. However, as disk capacity expands, your computer's performance may be slightly affected. Fixed disks and dynamic disks are commonly used in virtual machines

    What should I do if the images on the webpage cannot be loaded? 6 solutions What should I do if the images on the webpage cannot be loaded? 6 solutions Mar 15, 2024 am 10:30 AM

    Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

    How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

    How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

    PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

    The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

    How to open php on the web page How to open php on the web page Mar 22, 2024 pm 03:20 PM

    Executing PHP code in a web page requires ensuring that the web server supports PHP and is properly configured. PHP can be opened in three ways: * **Server environment:** Place the PHP file in the server root directory and access it through the browser. * **Integrated Development Environment: **Place PHP files in the specified web root directory and access them through the browser. * **Remote Server:** Access PHP files hosted on a remote server via the URL address provided by the server.

    How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

    How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

    How to deal with the problem that Laravel page cannot display CSS correctly How to deal with the problem that Laravel page cannot display CSS correctly Mar 10, 2024 am 11:33 AM

    "Methods to handle Laravel pages that cannot display CSS correctly, need specific code examples" When using the Laravel framework to develop web applications, sometimes you will encounter the problem that the page cannot display CSS styles correctly, which may cause the page to render abnormal styles. Affect user experience. This article will introduce some methods to deal with the failure of Laravel pages to display CSS correctly, and provide specific code examples to help developers solve this common problem. 1. Check the file path. First check the path of the CSS file.

    See all articles

    Public welfare online PHP training,Help PHP learners grow quickly!

    About us Disclaimer Sitemap

    © php.cn All rights reserved