SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow On-the-fly html from Dynamic PHP?

    Is there a PHP or perl program available that would allow me to convert all my dynamic .PHP pages to flat static .HTML pages?

    I would like to increase the performance of my site.

    The idea is I want the program to be called whenever I update a particular PHP page, and then it will go and rewrite the equivalent HTML page with the parsed PHP page.

    From what I hear there should be an easy solution, but no one has been able to give me a solid answer yet.

  2. #2
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    write a script to call each page and output using the command line.

    for example:

    <?php

    `c:\php\php.exe c:\wwwwroot\file1.php > c:\wwwtemp\file1.html`;

    //repeat as needed...

    ?>

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you talking about caching? Like as in Smarty or PEAR::Cache_Lite? Or do you want to stop using PHP altogether?

  4. #4
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Why would you ever want to do this? If its static (html) it CANT be (dynamic). Just save the page from the browser. Something that would convert it "on the fly" will decrease your preformance. Think about it. You would have to parse the php, save it as html, then display that. As oppose to just parsing the php and displaying. Its faster the way it is.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  5. #5
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The New Guy
    Why would you ever want to do this?
    He's not doing it on every load, just with a run-once-per-update php file to generate HTML. Poor man's cache - should work fine as ldivinag pointed out. Could probably loop over every file in the directory (http://www.php.net/readdir) so that he doesn't need to hand code the whole generate file though.

    Note that the example uses backticks ` instead of the normal '.

    Douglas
    Hello World

  6. #6
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Well than it wouldnt really be dynamic.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  7. #7
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The New Guy
    Well then it wouldn't really be dynamic.
    As dynamic as any cached PHP is.

    The bit in the subject which is wrong isn't the dynamic bit, but the "on-the-fly" bit. I think it should be "Static HTML from Dynamic PHP".

    Or ldivinag, HardCoded, and I could have miss read the post

    Douglas

    PS: he said "I want the program to be called whenever I update a particular PHP page" not "I want the program to be called whenever the PHP page is loaded in a browser."
    Hello World

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    yes, I would like to create "Static HTML from Dynamic PHP"

    if you observe these 2 pages:
    www.infizz.com/home.php
    www.infizz.com/index.html

    You can clearly see the second page loads incredibly faster. (I copied the source for that by hand)
    Somehow my host isn't all that great for php processing speed, and also I am not really getting more than 1 of my PHP pages (the index.php) indexed by either Google or Yahoo.

    Basically I am looking for loading speed. I do not want to run a script every time the page loads, only when it is updated.

    Also, I tried ldivinag's example like this, which didn't seem to work:

    <?php

    `c:\php-4.3.3-Win32\php.exe C:\Program Files\Apache Group\Apache2\htdocs\index.php > C:\Program Files\Apache Group\Apache2\htdocs\index.html`;

    //repeat as needed...

    ?>

    I am using Apache on my laptop for testing my scripts, with PHP and Perl installed.

    It would also be slightly preferable if this could be done in Perl as well.

    Any ideas?

  9. #9
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi nighthawk99,
    First I have been testing the html and the php from yours, taking care to empty my cache in between:
    I don't feel no obvious difference.

    For the performance out it should depend on your material means to/from disks/net. Depends on the load too.

    Perhaps your access to disk is quicker (cached) with a php script not changing (e.g. date) and you have so much CPU it's no problem to let it run a little.

    What is running under your PHP/HTML ?
    Is your OS saving something ? (apart $ for BG (not me) )

    No problem in PHP/HTML !
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still have the problem of Google/Yahoo not indexing more than 1 page on my site though!

    That is also a primary reason why I would desire html

  11. #11
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nighthawk99

    Also, I tried ldivinag's example like this, which didn't seem to work:

    <?php

    `c:\php-4.3.3-Win32\php.exe C:\Program Files\Apache Group\Apache2\htdocs\index.php > C:\Program Files\Apache Group\Apache2\htdocs\index.html`;

    //repeat as needed...

    ?>
    php.exe method won't work here, because it executes script outside of webserver context, what is generally impossible.

    You can use one of site grabbing utilities like wget or teleport to make "static" copy of your site.

  12. #12
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no no no

    I'm not sure if you guys understand what I am trying to do.

    I will state it as simply as possible:

    I have a forum
    Forums news and fresh posts are shown on the home page

    Each time a user makes a new post, it shows up in home.php
    Each time a user makes a new post, I want home.php copied to index.html


    How hard could it be?

  13. #13
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does having static html vs. php have to do with search engines? I have lots of sites built entirely with PHP and they get spidered by Google etc. all day long. Some of these I use caching on, some I don't. Seriously, just use PEAR::Cache_Lite if you're concerned about load times.

  14. #14
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    I was concerned because as soon as I changed my website to PHP, my site stopped being indexed.

    The only page that gets indexed regularly now is the INDEX.PHP. Everything else has been ignored for the past 4 months or so.

  15. #15
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As others have stated, you're really talking about two separate issues. You might want to start a separate thread in the Search Engine Optimization forum for why your site isn't being indexed by the search engines.

    As for making semi-dynamic web pages, which is what this thread title suggests, you might be interested to know that SitePoint does that with their home page. Basically, it is taking a PHP script and writing the results to a file on the server so that the resultant file (i.e., web page) is what gets called, not your PHP script, when that page is served. I think they actually refresh their home page about once a day.

    Hope this helps.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  16. #16
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    OK, I finally figured out how to do it!!!

    <?php

    ob_start();
    include ("index.php");
    $output = ob_get_contents();
    ob_end_clean();
    $content = $output;

    $fp = fopen("output.html","w");
    fwrite ($fp,$content . "\r\n");
    fclose($fp);

    ?>

    This writes the specified PHP to an HTML file.
    I am so happy I figured this out, lol

    However, I am wondering how this script would be called from within a Perl script...

    Also, I am wondering if there is perhaps an even faster way to do this, since this method seems to be a bit server-intensive.

  17. #17
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PEAR package HTTP_Request

    Hi
    Perhaps cleaner, you could use PEAR package HTTP_Request.
    Another advantage is you can make several page the same time if you want.
    PHP Code:
    require_once "HTTP/Request.php";

    $urlList = array(
        
    'http://www.example.com/'// to get the index.php
        
    'http://www.example.com/document.php'// a document
        
    'http://example2.com/foobar.php' // other site
    );
    $req =& new HTTP_Request();
    foreach (
    $urlList as $url) {
        
    $req->setURL($url);
        if (!
    PEAR::isError($req->sendRequest())) {
            
    $content$req->getResponseBody();
            
    // here you save the document
        
    } else {
            echo 
    "ERROR: Cannot reach {$url} !\n";
        }

    If you need you can even post data, change the protocol ...
    Don't you like it ?
    Bye
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  18. #18
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Calgary
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    wow, that is a great script - a great way to do it!

    Thanks!

    Also, is there a way to execute PHP scripts from Perl?

    I have a Perl program, and would like to call this script when the Perl program is executed.

  19. #19
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He, you just need to go in the PEAR's doc and examples, it's quite a copy
    Sounds strange for Perl
    But as PHP and Perl can be both Apache modules should be feasable.
    Thus if you don't need the scripts to transmit data arrange to call the Perl first thru submit buttons.
    If your script produce only files read it from PHP, perhaps check before e.g. it's newer as given other file if not OK war user.
    It should even be possible to make a system call, but then I cannot help much more by yours:

    We want Open Systems, no Windows, no Gates nor Bill but wide Open

    I don't want anymore to loose my head for dollars only one gets.
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source


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
  •