Jump to content

Recommended Posts

Hi Everyone,

 

I have a page that pulls the content from a MySQL db, it works fine how it is but I want my site to be more efficient.

 

When I add new content (via a form in the admin area) I want the site to generate a static HTML copy of the PHP page. This way the page only needs to call the db when I update the site rather than everytime somebody loads the page.

 

I found a few scripts that claim to do this but none of them seem to parse the php before creating the HTML page.

 

Has anyone any pointers on how to go about this?

 

Cheers

You would need to include the file using the URL to the .php page, then use ob_get_contents() to capture the resulting output - http://www.php.net/manual/en/function.ob-get-contents.php Then simply write the captured content to the file of your choice.

I actually just did this.

Put this on top for where you want to start capturing output:

 

ob_start();

 

put this on the bottom of the php

 

$HtmlCode= ob_get_contents();

ob_end_flush();

 

$fh=fopen('NewPage.html','w');

fwrite($fh,$HtmlCode);

 

fclose($fh);

 

 

Cheers for the code twittoris, I want to make a function so that I can use it for multiple pages. I came up with the following which works but when I call it, it inserts the the code into the page I call it from as-well. Is there a way to stop this or a better way to achieve what I am after?

 

function wwwcopy($dynamic,$static) {

    ob_start();

    require $dynamic;

    $temp= ob_get_contents();
    
    ob_end_flush();

    $fh = fopen($static,"w");
    fwrite($fh,$temp);
    fclose($fh);
    
    }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.