How does PHP execute a dynamic page to cache and generate static pages?
In ASP, the XMLHTTP object's open method is usually opened to execute a dynamic page, then the static HTML code generated after the dynamic page execution can be saved by a ADODB.stream object and then written to a text file.
In PHP, you can open the cache with Ob_start, let the string be written to the cache first, and then write the contents of the cache to a text file, the question is, how does PHP execute a dynamic page, in some articles, with the header ("location:adminnews.php") To execute a dynamic page, but I tried, so he only goes to this dynamic page, and does not output the content of the dynamic page to the cache, my code is this, I want to adminnews.php execution results (generated HTML code) all write to jb51.html, what should be done
Ob_start (); Open buffer
echo "hello\n"; Output
Header ("location:adminnews.php"); redirect the browser to index.php
$cacheStr =ob_get_contents ();
$handle =fopen ("jb51.html", "w");
Fwrite ($handle, $CACHESTR);
Ob_clean ();
?> generating a static page
Share to:
------Solution--------------------
Ob_start (); Open 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 ();
------Solution--------------------
With $wstr=file_get_contents (' http://www.baidu.com '); This function goes to execute a URL address.
------Solution--------------------
References:
file_get_contents can get the results of adminnews.php execution.
I tried not to Ah, using this to get to the adminnews.php source code, rather than adminnews.php execution results, I want to be executed after the generated HTML code, not the original PHP code AH.
Ob_start (); Open buffer
echo "hello\n"; Output
$cacheStr =file_get_contents ("adminnews.php"); //
$handle =fopen ("jb51.html", "w");
Fwrite ($handle, $CACHESTR);
Ob_clean ();
?>
How do you access it through the browser, file_get_contents fill that address inside