Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Any way to create .html file from a .php file with php command?

    Suppose I have a php file, index.php that contains scripts that accessed mysql database and produce a nice looking webpage.

    In order to reduce the load of Mysql query, I would love to have my index.php converted into a static index.html file for every half hour so that browser can be set to view just the index.html.

    Can anyone help me for any trick or way to be able to convert this php into html file through a php script? Note that I do not have shell access to perform wget/GET command.

    Thanks in advance for your help.


  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    PHP Code:
    <?php
    $page
    =file_get_contents('http://yourdomain.com/index.php');
    $fp=fopen('index.html','w+');
    fputs($fp,$page);
    fclose($fp);
    ?>
    ...that just creates the file though, to do it automatically every 1/2 hour would normally require a cron job (which would use wget or php itself)

    if you do not have cron available then anything else is a hack.. but you could have a hidden iframe in your index.html that called say rebuild.php, rebuild.php would check the database or a textfile for the last time the file was rebuilt, and if the time was up would use the above script.... such scipts are best avoided though if you have cron available.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Location
    Southampton
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could always try caching the site in apache, so it will not process the page on every request

    # MONTH
    <FilesMatch "\.(php)$">
    Header set Cache-Control "max-age=2592000"
    </FilesMatch>

    # WEEK
    <FilesMatch "\.(php)$">
    Header set Cache-Control "max-age=604800"
    </FilesMatch>

    # DAY
    <FilesMatch "\.(php)$">
    Header set Cache-Control "max-age=43200"
    </FilesMatch>


  •  

    Posting Permissions

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