I have kind of a special requirement that is, I'm using a Raspberry Pi 2 B device to feed some data to a mysql database in a cloud serve. So I have installed LAMP stack on raspberry pi and config my script there. And task of it is insert some values to the remote server (cloud) mysql database (I have opened ports for it). And script should run each 30 seconds.So I do not need to have browser support for this as we do not need to show any details on Raspberry Pi.After first run of the script it should not stop ever , should run 24x7 in all 365 days.
So my question is how to run my script in each 30 seconds, seems I have few options
- Using a PHP thread (seems need browser support or first time script running through bash, if some exception occurs in a moment script will stop running it again till it manually reset , database connection will establish one time so time waste for establishing it again and again will prevent)
- Using a Cronjob (seems no need of browser support even for first run, guess since it is run complete script again reduce terminate of the script , database connection will establish again and again for each run so that time will waste )
My main concerns are never stop the script , should take minimal time to run the script once and server should not kill by the process as it hit in each 30 seconds. please suggest your opinions sometime there may be an another way which is more efficient than above methods