How does PHP execute a dynamic page to the cache and then generate a static page?

Source: Internet
Author: User
How does PHP execute a dynamic page to the cache and then generate a static page?

In ASP, the open method of the XMLHTTP object is usually used to open a dynamic page for execution. the static html code generated after the dynamic page is executed can be a adodb. the stream object is saved and then written to a text file.

In PHP, you can use ob_start to open the cache, so that the string is first written to the cache, and then the content in the cache is written to a text file. The problem is, how does PHP execute a dynamic page, in some articles, we use header ("location: adminnews. what should I do in php "example?
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
Header ("location: adminnews. php"); // redirects the browser to index. php.

$ CacheStr = ob_get_contents ();
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>


Reply to discussion (solution)

Ob_start (); // open the buffer
Echo "Hello \ n"; // output
Include ("adminnews. php"); // load and run

$ CacheStr = ob_get_contents ();
$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();

Use $ wstr = file_get_contents ('http: // www.baidu.com '). you can use this function to execute a URL address.

Is file_get_contents a built-in function in php?

Is file_get_contents a built-in function in php?

Yes, see file_get_contents

Is file_get_contents a built-in function in php?
Yes. you can refer to the manual for reference.

File_get_contents can get the result of adminnews. php execution.

File_get_contents can get the result of adminnews. php execution.

I tried it. I can't use it to get adminnews. php source code, rather than adminnews. the php execution result is the html code generated after execution, rather than the original php code ..
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
$ CacheStr = file_get_contents ("adminnews. php ");//

$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>

File_get_contents can get the result of adminnews. php execution.

I tried it. I can't use it to get adminnews. php source code, rather than adminnews. the php execution result is the html code generated after execution, rather than the original php code ..
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
$ CacheStr = file_get_contents ("adminnews. php ");//

$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>

How did you access it through the browser? in file_get_contents, enter the address

File_get_contents can get the result of adminnews. php execution.

I tried it. I can't use it to get adminnews. php source code, rather than adminnews. the php execution result is the html code generated after execution, rather than the original php code ..
Ob_start (); // open the buffer
Echo "Hello \ n"; // output
$ CacheStr = file_get_contents ("adminnews. php ");//

$ Handle = fopen ("jb51.html", "w ");
Fwrite ($ handle, $ cacheStr );
Ob_clean ();
?>

The example I gave is so obvious that I still don't understand it?

Now, adminnews. php is written as an absolute path. it is not executed if only the file name is written.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.