Welcome to the Cumulus Support forum.
Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080
Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080
Question for the PHP gurus...
Moderator: daj
-
fractonimbus
- Posts: 159
- Joined: Thu 03 Feb 2011 1:15 am
- Weather Station: WH1091
- Operating System: Windows 7 on a Dell Vostro
- Location: Canberra
Question for the PHP gurus...
(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
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
- daj
- Posts: 2041
- Joined: Tue 29 Jul 2008 8:00 pm
- Weather Station: WH1081
- Operating System: Pi & MX
- Location: SW Scotland
- Contact:
Re: Question for the PHP gurus...
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
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
-
fractonimbus
- Posts: 159
- Joined: Thu 03 Feb 2011 1:15 am
- Weather Station: WH1091
- Operating System: Windows 7 on a Dell Vostro
- Location: Canberra
Re: Question for the PHP gurus...
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.
- daj
- Posts: 2041
- Joined: Tue 29 Jul 2008 8:00 pm
- Weather Station: WH1081
- Operating System: Pi & MX
- Location: SW Scotland
- Contact:
Re: Question for the PHP gurus...
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.
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.
-
fractonimbus
- Posts: 159
- Joined: Thu 03 Feb 2011 1:15 am
- Weather Station: WH1091
- Operating System: Windows 7 on a Dell Vostro
- Location: Canberra
Re: Question for the PHP gurus...
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
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
- steve
- Cumulus Author
- Posts: 26672
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: Question for the PHP gurus...
If the file is uploaded by Cumulus, you could get Cumulus to execute a PHP script on the server after each upload (using wget).
Steve
-
fractonimbus
- Posts: 159
- Joined: Thu 03 Feb 2011 1:15 am
- Weather Station: WH1091
- Operating System: Windows 7 on a Dell Vostro
- Location: Canberra
- daj
- Posts: 2041
- Joined: Tue 29 Jul 2008 8:00 pm
- Weather Station: WH1081
- Operating System: Pi & MX
- Location: SW Scotland
- Contact:
Re: Question for the PHP gurus...
How do we do thissteve wrote:get Cumulus to execute a PHP script on the server after each upload (using wget).
Have a missed something in Cumulus?
- daj
- Posts: 2041
- Joined: Tue 29 Jul 2008 8:00 pm
- Weather Station: WH1081
- Operating System: Pi & MX
- Location: SW Scotland
- Contact:
Re: Question for the PHP gurus...
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
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
- steve
- Cumulus Author
- Posts: 26672
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: Question for the PHP gurus...
On the internet settings screen, you can configure an external program to be run after each upload (normal and/or realtime).daj wrote:How do we do this![]()
Have a missed something in Cumulus?
Steve