Page 1 of 1
Question for the PHP gurus...
Posted: Mon 06 Jun 2011 11:43 am
by fractonimbus
(of which I am definitely not one!)
I have a file that is uploaded to my server roughly every minute.
In PHP I want to watch the time stamp on that file and read the file (etc) when the time stamp changes (ie when the latest upload has occurred).
I have been thinking along the lines of a while statement, but it's evident I don't understand how it works, as the following pseudo code doesn't seem to work:
$f = $filename; // incoming file name
$t1 = filemtime($f); // get time stamp
$t2 = $t1; // set up comparison variable
while ($t1 = $t2): //wait for it to change
// clearstatcache(); needed?
$t1 = filemtime($f);
endwhile;
// now do something
How do I keep a permanent watch on the incoming file and take action when the time stamp changes? Can anyone steer me in the right direction?
Thanks
DN
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 11:51 am
by daj
PHP script only executes once, when the user loads it on a web browser and it (PHP) is executed by the server and the results delivered to the browser as HTML.
If you want to have something running constantly you either need to leave a browser window open and write some Javascript to reload the page every minute, or run a background task on your webserver that runs the PHP code. This is referred to as a CronJob (if you are using a Linux webserver) -- depending on who hosts your site you may (or may not) have access to CronJobs
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 11:56 am
by fractonimbus
OK, thanks. That explains why it doesn't work:-) I'm on a Linux server so the cronjob approach would be feasible. And Javascript/Ajax are also sensible.
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 11:59 am
by daj
Are you self-hosting or hosted? As I say, some hosts will not allow you access to run CronJobs, especially every one minute
JS/JQuery will only be relevant if you need the browser to do the work as JS only runs on the Browser and never on the server.
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 12:10 pm
by fractonimbus
Hosted
Yes, I was thinking it through and the cron job would be the only way, short of having a permanently connected browser
So I need to do the data assembly locally and upload it from time to time, I think. I was hoping to avoid that.
Thanks, David.
DN
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 12:15 pm
by steve
If the file is uploaded by Cumulus, you could get Cumulus to execute a PHP script on the server after each upload (using wget).
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 1:48 pm
by fractonimbus

Clever idea! Thanks, Steve.
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 5:43 pm
by daj
steve wrote:get Cumulus to execute a PHP script on the server after each upload (using wget).
How do we do this
Have a missed something in Cumulus?
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 5:47 pm
by daj
Actually, I see what you mean now -- run an external program from within Cumulus
You can also use 'Toolbox' to run remote commands on the webserver at set times, and do the upload too if it does not fit into the Cumulus schedule
Re: Question for the PHP gurus...
Posted: Mon 06 Jun 2011 5:48 pm
by steve
daj wrote:How do we do this
Have a missed something in Cumulus?
On the internet settings screen, you can configure an external program to be run after each upload (normal and/or realtime).