php after the page has loaded (post load php)
Moderator: General Moderators
php after the page has loaded (post load php)
Is there a way of getting a page to do the php comand after the rest of the page has loaded and been diplayed. I have found refrenced to iframe and DHTML, but im not sure how to do this yet.
Basicaly I have a stock ticker that downloads RSS feed to a local folder, this takes quite a while, how ever this would be acceptable if the php downloader was to run while the rest of the page was being displayed, anyone know how to do this, or what i should be looking at?
Basicaly I have a stock ticker that downloads RSS feed to a local folder, this takes quite a while, how ever this would be acceptable if the php downloader was to run while the rest of the page was being displayed, anyone know how to do this, or what i should be looking at?
umm sounds like an AJAX problem... have you heard of AJAX? Look here:
http://blog.coderlab.us/rasmus-30-second-ajax-tutorial/
http://blog.coderlab.us/rasmus-30-second-ajax-tutorial/
Re: php after the page has loaded (post load php)
I think you're better of with a script that runs on the background to fetch the RSS feeds. And then let your webpages use those cached versions... Downloading them for every client will get your host banned from most feeds anyway...
almost there I think:
Saved in the local file as JSsource.js:
-------------------------------
on my page that loads the data use:
<BODY onLoad="javascript:sndReq()" >
<script type="text/javascript" src="JSsource.js"></script>
-----------------------------
the php code (fetchRSS2.php) contains:
Saved in the local file as JSsource.js:
Code: Select all
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{ro = new XMLHttpRequest();}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'fetchRSS2.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
/* nothing here, since the page doesnt have to be updated */
}
}on my page that loads the data use:
<BODY onLoad="javascript:sndReq()" >
<script type="text/javascript" src="JSsource.js"></script>
-----------------------------
the php code (fetchRSS2.php) contains:
Code: Select all
function file_put_contents_php4 ($location, $whattowrite) {
if (file_exists($location)) {
unlink($location);
}
$fileHandler = fopen ($location, "w");
fwrite ($fileHandler, $whattowrite);
fclose ($fileHandler);
}
echo file_put_contents_php4("aFile.txt",$str);works, but is it updating once the page is loaded (its hard to tell as my broadband is too fast, obvioulsy not everyones will be)
this litle bit here:
Does this run as on load only, or is the sript run as soon as it hits:
this litle bit here:
Code: Select all
<BODY onLoad="javascript:sndReq()" >
<script type="text/javascript" src="JSsource.js"></script>Does this run as on load only, or is the sript run as soon as it hits:
Code: Select all
<script type="text/javascript" src="JSsource.js"></script>
Last edited by RICKYJ on Mon Nov 20, 2006 8:27 am, edited 1 time in total.
anyone know if this is the method that i should be using in javascript?
or should it be something like
Code: Select all
<BODY onLoad="javascript:sndReq()" >
<script type="text/javascript" src="JSsource.js"></script>Code: Select all
<BODY onLoad="javascript:sndReq()" type="text/javascript" src="JSsource.js">- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: php after the page has loaded (post load php)
Why is it taking quite a while? Wouldn't it make sense to optimize the download as opposed to writing a new codebase to allow for slow loads in the background?RICKYJ wrote:Basicaly I have a stock ticker that downloads RSS feed to a local folder, this takes quite a while, how ever this would be acceptable if the php downloader was to run while the rest of the page was being displayed, anyone know how to do this, or what i should be looking at?