caching output of scripts as html - ResellerRatings Store Ratings
Comparison shop, read reviews, find savings, at ResellerRatings.com.
Comparison shop, read reviews, find savings, at ResellerRatings.com.
Comparison shop, read reviews, find savings.
What are you shopping for?
Digital Cameras Plasma and LCD
HDTv's iPods and Other
MP3 Players PC Laptops Camcorders

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-31-2002, 02:51 PM   #1 (permalink)
Registered User
 
Join Date: Jun 2002
Location: Northern California
Posts: 68
memobug is on a distinguished road
caching output of scripts as html

Greetings,

I have a couple of scripts for news and calendar that change every couple of days. Most are written in perl, but some are in php.

Is there a way to automate the process of running these scripts and capturing their output (which is plain html) so that it can be included by server side includes?

Every couple of days, I run the scripts, view source, and save as "componentX.html" manually, and I figure there has to be a better way.

I can use cron to run the script, but how about redirecting its output to an html file? I'm on a Linux server.

Thanks,

Matt

__________________
My photopost hacks:
Terms of Use, Thumbnail Includer, My Gallery
memobug is offline   Reply With Quote
Old 09-01-2002, 01:02 PM   #2 (permalink)
Registered User
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,565
strangerstill is on a distinguished road
Well, with php it's easy enough - you just need the standalone binary rather than the Apache module, then pass the .php file to the php binary - e.g. in Dos/Windows run
php.exe "file.php" > "out.html"
I'd guess it's similar in Linux, and there must be something similar for perl.
strangerstill is offline   Reply With Quote
Old 09-03-2002, 07:48 PM   #3 (permalink)
Registered User
 
Join Date: Aug 2002
Location: Pennsylvania USA
Posts: 6
DragonAss is on a distinguished road
Send a message via ICQ to DragonAss
Food

If you have access to cron jobs, would a simple shell script be practical?

Say, something like:


#!/bin/sh

/this/is/job/num1.cgi > /path/to/componentX.html
/this/is/job/num1.php >> /path/to/componentX.html
/this/is/job/num2.cgi >> /path/to/componentX.html
/this/is/job/numX.php >> /path/to/componentX.html

exit(0);


----------

Then just run this shell script as the cron job.

(first line uses only one > to erase the file first
and subsequent lines use two >> for append)

This assumes the componentX.html is on the same machine.
Piping it to another machine is still possible though.
DragonAss is offline   Reply With Quote
Old 09-03-2002, 09:46 PM   #4 (permalink)
Registered User
 
Join Date: Jun 2002
Location: Northern California
Posts: 68
memobug is on a distinguished road
This is fantastic. I really appreciate your help! Maybe this is so basic that everyone knows it, but I read dozens (probably a hundred) pages on cron and caching and none of them touched this.

1) (Is that first ">" a typo? should be ">>" like the rest?
2) How would you reference an off-server script as the source?

THANKS A MILLION!

Matt
__________________
My photopost hacks:
Terms of Use, Thumbnail Includer, My Gallery

Last edited by memobug : 09-03-2002 at 09:55 PM.
memobug is offline   Reply With Quote
Old 09-03-2002, 09:58 PM   #5 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,955
vass0922 is on a distinguished road
The first > will create the file
The >> will append to the file

__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 09-04-2002, 12:10 AM   #6 (permalink)
Registered User
 
Join Date: Aug 2002
Location: Pennsylvania USA
Posts: 6
DragonAss is on a distinguished road
Send a message via ICQ to DragonAss
Quote:
2) How would you reference an off-server script as the source?
Good question via shell (I know you can ping from the shell and do other net things... so what you would use depends on what's installed or what's built in -- offhand I forget what some of the possiblities are).

Another way might be to write a php script that gets the file from a URL and pipes the output as before. The following is NOT tested, just what seems like a possible approach for the "/this/is/job/num1.php":

PHP Code:
<?php

$fp
= fopen ("http://www.php.net/", "r");
fpassthru($fp);
exit;

?>
Just replace the URL ( http://www.php.net ) with the URL to your script. Since PHP and CGI are server-side, they'll pump out the same info to a browser or a script (sans cookies and other complications ). I don't always have good luck with the short & sweet version of fopen() and use the fsockopen() instead... but fopen() ought to work just as well in most cases.

NOTE 1: this method will not download any pics unless they're full URLs. In fact. if the HTML code does NOT show relative links (pics, downloads, whatever with short links), it'll work OK from another server. Otherwise, you'll need to processes the return page and save or, better, fix all the relative links up somehow. Could be some work and I can't think of any quick fixes off hand. Perhaps a shell using lynx to download the entire page might handle this job better? I dunno much about Lynx.

NOTE 2: This is a pipe to a pipe. You might want to see what happens when your remote script URL is broken... in case a site goes down during "live time". A simple "if(something broken) { return;}" might fix it.

NOTE 3: Security... if you are running this as a normal user, then you should be okay since it's HTML and not an executable you're making here. Still... be aware that others can put things onto your server with this. Of course, you still control which URLs may donate to your file.

If things are simple you could be done.

Good luck!

Because things are rarely simple.
DragonAss is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Most Active Discussions
Cyberpowerpc.com Any Good? (10)

Recent Discussions
Cartman Covers Lady Gaga's (0)
tactical leds llc (0)
Cyberpowerpc.com Any Good? (10)
Like New Wacom 12x19 Intuos 3 +.. (1)
For Sale BFG GTX285 OC2 with 10.. (2)
www.szprice.com - any experienc.. (1)
Games, Cables, PCI cards, and m.. (5)
Buymoreshopping.com? Wigix.com (3)
I want your old/new unused pc p.. (6)
:mad: Spam At-hon (3)
Fall-Winter Cleaning Sale (1)
DON'T BUY.COM Advisory (232)
Is certifiedwatchstore.com legi.. (1)
Beware of used XBOX 360's (12)
Cheap Used Computers (0)

All times are GMT -6. The time now is 04:43 PM.