Jump to content

How can I cache this simple Ebay dynamically-generated list?


contractor

Recommended Posts

The following HTML page successfully displays a short, dynamically-generated real-time list of currently available Ebay items using a simple Javascript external link:

 

[begin HTML snippet]

 

<html>
<head>
    <title>Retrieve current Ebay list</title>
</head>
<body>
List of Ebay items follows:<br />
<p>
<script type="text/javascript" src="http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=fjwvl%7Cks&bdrcolor=ff0033&bin=y&cid=0&eksize=1&encode=ISO-8859-1&endcolor=FF0000&endtime=y&fbgcolor=FFFFFF&fntcolor=000000&fs=0&gallery=y&hdrcolor=FFFFCC&hdrimage=1&hdrsrch=n&img=y&lnkcolor=0000FF&logo=1&num=25&numbid=y&paypal=n&popup=y&prvd=1&query=%22microsoft%22&r0=4&shipcost=y&sid=ms&siteid=0&sort=MetaEndSort&sortby=endtime&sortdir=asc&srchdesc=y&tbgcolor=FFFFFF&title=&tlecolor=FFFF99&tlefs=0&tlfcolor=000000&track=2277761&watchcat=39721&width=550"></script>
</p>
<hr />
</body>
</html>

 

[end HTML snippet]

 

This HTML works fine, but since all my web visitors will be displaying the same retrieved Ebay list then to reduce system overhead I would like to retrieve that Ebay list only once every 60 seconds or so. How then might I retrieve this list from Ebay and then cache it locally? 

 

Note that I am a PHP noob and I tried converting the above to run inside of a cached PHP page, but I never figured out how (within that cached PHP context) to initiate the external javascript request to Ebay and then save the resulting list and render it to the browser properly on a cached basis.

 

Rather than confuse the issue by displaying my unsuccessful code I thought I would just show the basic HTML code (which works fine) and see if anyone had any ideas on how to cache the output properly - and within PHP if that would do the job. ::)

 

I THINK that the solution as similar to caching a retrieved external news feed but I don't know enough to put it together yet. Any suggestions greatly appreciated.

 

 

Link to comment
Share on other sites

Depending on who you're hosting with your webhost might provide you with access to Cron, which will allow you to specify a script to run every *minutes *hours *days *months

 

If you were to make a small script which did a file_get_contents of the page that displays the HTML you posted above you could save the return of the file_get_contents into a new HTML file. This script you would make run via the cron every minute or so.

 

So for an example, say the page that displays the dynamic real time list of Ebay items is called uhh "MyEbayItems.html"

 

This is the file you would run with Cron, all it does is basically get the output from "MyEbayItems.html" and saves it to another file.

 

<?php
/* Edit this \/ */
$EbayItemCache = file_get_contents("http://www.YOURWEBSITE.com/PATHTO/MyEbayItems.html");

/* Dont touch below here */
$CacheFile = "MyEbayItems_Cache.htm";

if(file_exists($CacheFile))
{
unlink($CacheFile);
}

$CacheFile = fopen($CacheFile, "w");
fputs($CacheFile, $EbayItemCache);
fclose($CacheFile);

?>

 

Now, to display the now cached version you would link users to this (name the file anything you want)

 

<?php

$CacheFile = file_get_contents("MyEbayItems_Cache.htm");
echo $CacheFile;

?>

 

 

I hope I made some semblance of sense...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.