Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Temp Webpage While Creating Final PHP Webpage

by Your Mother (Archbishop)
on Apr 15, 2020 at 05:27 UTC ( [id://11115546]=note: print w/replies, xml ) Need Help??


in reply to Temp Webpage While Creating Final PHP Webpage

Assuming I understand you–

  1. Request to Perl to initiate creation of PHP page.
  2. Perl serves a very small dummy/placeholder page immediately saying “Please wait…” perhaps forking such that parent serves page and exits while child creates PHP–
    1. The new page has a small Ajax routine; I like jQuery, there are MANY other good libraries.
    2. The Ajax polls for the PHP resource every $x milliseconds.
    3. When the PHP page is ready, the JS replaces the location of the page, effectively redirecting; but not quite the same and there are other ways to do this and they have various implications in browser history.

Barring JS, you can do this with meta refresh and redirect tricks but it’s messy and gross. :P Might/should include <noscript/> tags such that non-JS enabled browsers will see they cannot properly use the resource.

Replies are listed 'Best First'.
Re^2: Temp Webpage While Creating Final PHP Webpage
by bobinyec (Acolyte) on Apr 15, 2020 at 10:54 UTC

    You understand the problem perfectly. The file on the server that I would be looking for already exists, but would be old. I would need to poll to find out the date of the file. When it has been updated and has a current date and time, I would change the location.

    Can you recommend an AJAX routine to do this? A small code snippet would be very much appreciated.

    Thanks - jb

      Untested but semi-complete outline. I’m fair at this stuff but beware of cargo culting. Try to understand everything that’s going on if you’re going to use it. Any errors I make become your responsibility. :P

      #!/usr/bin/env perl use strictures; use CGI ":standard"; use Date::Calc "Today"; my $pid = fork(); if ( $pid ) { hold_page(); } elsif ( $pid == 0 ) { write_php(); } else { die "Couldn't fork\n"; } exit 0; sub hold_page { print header(), start_html("OHAI"), h1("Keep panties unbunched!"), noscript("It's", (Today())[0] . ", for the love of crabcakes!" +, "Enable JS!"); print <<'_HTML_'; # <- single quote matters. <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJ +o=" crossorigin="anonymous"></script> <script> function checkPHP() { $.ajax({ url: "FILL THIS IN" ,timeout: 1000 }) .done( function( data ) { window.location.href = "FILL THIS IN"; }) .fail( function( jqXHR, textStatus, errorThrown ) { if ( textStatus === "timeout" ) { setTimeout(checkPHP, 2000); return; // Keep trying. } else if ( jqXHR.status == 404 ) { setTimeout(checkPHP, 2000); return; // Keep trying. } else { alert("WAT? " + jqXHR.status + " " + errorThrown); } }); } $(function(){ checkPHP() }); </script> _HTML_ print end_html(); } sub write_php { # Execute script that will write page # found at URL "FILL THIS IN" }

        Thanks - jb

        Thanks. I'll give it a look. - jb

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found