Trying to find a way to run a php script in the background

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
DaveR
Forum Newbie
Posts: 2
Joined: Sat Aug 02, 2003 11:39 pm

Trying to find a way to run a php script in the background

Post by DaveR »

G'day everyone

My page can't be refeashed or the person on it will be kicked out of a voice chat session.

Also trying to do this without going server side.

I'm looking for a way so that about ever 5 mins the users has the page open, a timer counts down to zero and then run's a php script in the background that will refresh thier status as being logged on in a mysql db.

knowing full well a php page can't be be run without a refresh I think the only way is to use javascript to get the countdown clock to count down.

I have the countdown clock working fine.
The logon script is working just fine so when they first come to the page they are flaged as being logged on in the db.

the database is setup in a way so anyone that is no longer there in 5 mins the record is deleted this is handled when anyone comes into the site all old records are dropped.<this allows for droped users or those that don't logout correctly

So knowing I'm still learning I'm looking for a way to run a php script from js without having to open a tiny window.

I have tryed using the following statements
JS function;
function callScript(){
grabImage = new Image(0,0); grabImage.src="/system/logit.php"; void(0);
}

which does seem to work fine the first time the script is run. I have this is alittle function with my js and I can call it when it's in the main flow of the program. but once I try adding it to my clock script it fails to function. nor can I call it from an onclick of a button.
Also no errors are genrated even if I remove the void(0);

run by itself in the main flow it runs the script just fine and updated the database but can't get it to work from being called by anything else. :-(

Any ideas?

DaveR
DaveR
Forum Newbie
Posts: 2
Joined: Sat Aug 02, 2003 11:39 pm

Post by DaveR »

Ok I think I have worked out part of my problem.

Because the image gets stored in cache it won't reload on the next call.. so is there a way to force a reload of the image?

Dave
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Use an IFRAME and hide it in a DIV on your page...

Code: Select all

<div style="position:absolute;visibility:hidden;top:0;left:0">
<iframe name="runphp" src="my_php.php"></iframe>
</div>

You can then have a simple JS function that will update/reload the IFRAME and not the entire page (this script goes in your main page, not the iframe)...

Code: Select all

<script>
function ReloadPHP()
&#123;
window.frames.runphp.location="my_php.php";
&#125;

setInterval("ReloadPHP()", 300000); //every 5 minutes
</script>
derek
Forum Newbie
Posts: 17
Joined: Sat Aug 16, 2003 11:31 am

Post by derek »

Hey ! Good code Gen.
I also think that by hiding the DIV tag and show it again when we need is a good way to execute the PHP file. I think that now a days commercial CHAT Progs like PHPLive etc are may be using the same way to refresh the client chat window.
Post Reply