Click to See Complete Forum and Search --> : how to endlessly watching a table in a database in php


mani-X
05-19-2008, 04:58 PM
i would like to have a script that will endlessly watching the value of a field in a table i.e. 1)if the value is R it will print in the browser "running process"

2)if the value is N it will print in the browser "there is no files to for treatment"

3) if the value is W it will print "waiting for files to be treated'

I know how to make the script but i do not know how to make it looking endlessly in the field, i do not want to make an infinite loop since it can cause the server to be frozen.

Any help will be appreciated

Yelgnidroc
05-19-2008, 05:18 PM
Why do you need to endlessly watch something?

Why not just check the field when you need to see what's happening?

If you really do need to endlessly watch a field, consider The Meta Refresh Tag

mani-X
05-20-2008, 10:15 AM
Yelgnidroc,
the reason i need top watch this field endlessly is just i have a cron script that will execute each five minutes and add a value in this field.

since Cron cannot send output to the web browser therefore i need to watch each time cron execute to make a script that will send the message.

my cron script is started each 5 minutes.

perharps i will need to have this script sleep each 1 minute and send the output cause using infinite "while(1)" loop can damage the server.

Phill Pafford
05-20-2008, 01:18 PM
you could do this in 2 steps.

Step 1:

You have done already with your cron script. you will just need to add one more step. write the output or output flag to a text file.

make sure you include a timestamp in the new text file at the end of the file. (Append)

Step 2:

Create another script to read the text file, go to the last enrty and search for the timestamp. do you validation/calculations here and output accordingly. This could be in perl or php. could also update a new table with the results as well so you can go back and look at the history.

Run this new script in cron as well, maybe space it out to run.

Hope this gives you some ideas.

TJ111
05-20-2008, 01:55 PM
You could just put a <meta> refresh that refreshes the page every 5 minutes. It'd be a really simple solution, albeit not the prettiest.

mani-X
05-20-2008, 02:39 PM
Phil pafford,
i really like your point of view and i would like to go for it cause it makes a lot of sense to my need.

I really concur with the step 1.

the step 2 i still agree with the part that will read the file but i will get stuck up for the output to the web browser since this script will be run by cron job.

I need only to find a way to print the output to the web browser.

Tj111,
I will take your alternative in consideration but as you say it is not the best way to do this.

TJ111
05-20-2008, 04:05 PM
If I needed a more complete solution, I would just use Ajax to poll the server every 15-30 seconds or so and display the results. That wouldn't be significantly harder to implement and prevents having to parse text files.

mani-X
05-20-2008, 04:51 PM
TJ111,
i don't know Ajax at all, I will need to look a look tonight cause i'm desperate and i need to have this work.

how you can have this work?

i will search by my side too.

TJ111
05-20-2008, 05:03 PM
Give this article a look over, might get you started on Ajax.
http://eloquentjavascript.net/chapter14.html

mani-X
05-20-2008, 05:06 PM
Thanks TJ111,
I will take a close look to see how Ajax works.