Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Can I automatically save PHP generated pages as HTM?

  1. #11
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by wkenny View Post
    The search engines would probably not index the pages because of the re-direct. Yahoo show how they handle re-directs and, unless I've misinterpreted, when a re-direct is to a page in the same domain they index the referring page rather than the target page
    I should think you have misunderstood. The redirect will either be internal (the Web server itself chooses a different file) or via a HTTP redirect. A search engine wouldn't even know about the former, and it would be completely broken if it ignored the latter.

    Search engines will not process "redirects" implemented through client-side scripts, and they are wary of meta element "redirects". The latter can easily be abused.

    Can you post a link to where you read this information?

    Text on one of the links from the page you referred me to says " It is easy to directly pre-generate a page to its static form" but does not say how. This is what I need.
    What can be done is to check the modification time of each source that makes up a document, and compare it against the time of the generated document (if it exists). If the generated document is older than the newest source, it is regenerated. Eventually, a temporary redirect is returned that refers to the generated version.

    Something along the lines of:
    PHP Code:
    <?php
    /* This file name needs to be determined somehow. The name of the PHP file is sensible, but not
     * necessarily appropriate. Do no use an absolute path (without making the necessary changes,
     * below).
     */
    $destination '...';
    /* A list of files used to construct the document. */
    $sources = array('header.fragment''content.fragment''footer.fragment');

    if (!
    file_exists($destination '.lock')) {
        
    touch($destination '.lock');
    }
    $lockFile fopen($destination '.lock''r');
    flock($lockFileLOCK_SH);
    if (
    isStale($destination$sources)) {
        
    /* Upgrade lock before writing. */
        
    flock($lockFileLOCK_EX);
        
    $destinationFile fopen($destination'w');
        
    ob_start();
        
    /* Output contents... */
        
    fwrite($destinationFileob_get_contents());
        
    fclose($destinationFile);
        
    ob_end_clean();
    }
    flock($lockFileLOCK_UN);
    fclose($lockFile);

    /* Change the domain name as necessary. */
    $destinationUri 'http://www.example.com' rtrim(dirname($_SERVER['PHP_SELF']), '/')
        . 
    '/' $destination;
    header('Location: ' $destinationUri);
    ?>
    <!DOCTYPE html "-//W3C//DTD HTML 4.01/EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html>
        <head>
            <title>Continue to <?php echo $destinationUri?></title>
        </head>

        <body>
            <p>Please continue to <a href="<?php echo $destinationUri?>"><?php echo $destination?></a>.</p>
        </body>
    </html>
    <?php
    function isStale($destination$sources) {
        if (!
    file_exists($destination)) {
            return 
    true;
        }

        
    $generationTime filemtime($destination);
        foreach (
    $sources as $source) {
            if (
    $generationTime filemtime($source)) {
                return 
    true;
            }
        }
        return 
    false;
    }
    ?>

    In principle it's simple, but it can get awkward with many sources without some abstraction. One also needs to check that it's less resource-consuming to test the modification times than it is to generate the document (as well as cache-related headers like ETags, and Last-Modified, and Content-Length to facilitate persistent connections).

    Mike

  2. #12
    Join Date
    Nov 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to remove numbers from file then save it

    Hi again,

    Come accorss other issue while solving it. SO need your suggestion again.

    I can remove spaces using trim function,

    PHP Code:
    include (trim($files[$i]));


    But Suppose if file name is index2.php, then how can I remove space and (OR only number) number so that I can save file as index.html

  3. #13
    Join Date
    Nov 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation comes across strange issue

    Hi everyone,

    While running this script for the website I come across one new issue.
    I have found solution by using ereg_replace method to remove number from filename.

    But new issue come accross while testing site from last 2-3 days.
    When I run this script then It get all data from index.php files and save that data as index.html file. But I have seen 3-4 times that once I created the index.html file all data get changed without running script again and it happened 3-4 times.
    Also data I get is different than compare to data I usually get on running script.

    This is very bad news because if I update file and leave running the website as default index.html page then users on website cant see what it should be displayed on website.

    So question from above all programmers, might be you passed through this error. can you please explain about this bit and solution.

    thanks in advance


    imi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •