[php] Reloading php file outside of browser

I need to be able to have a PHP file that loads itself outside of the browser.  I want to avoid using a cron tab if I can, but I am not sure how to do this with php, to have it run in an interval on the server every second or faster.  

The script is just going to be loading a JSON file and checking for changes to it and then uploading any changes to it to a database.

Thanks!
prileyosborneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

InsoftserviceCommented:
try out this one

refresh ur page with jquery.

<script type="text/javascript">

$(document).ready(function(){
   var j = jQuery.noConflict();
      j(document).ready(function()
      {
            j(".refreshMe").everyTime(5000,function(i){
                  j.ajax({
                    url: "refresh-me.php",
                    cache: false,
                    success: function(html){
                        j(".refreshMe").html(html);
                    }
                  })
            })
      });
   j('.refreshMe').css({color:"red"});
});



</script>
0
theodorejsalvoCommented:
You can run php scripts from the command line if you have php installed.  For example, in linux:

$
php myscript.php

Open in new window


Any print statements will go to standard output instead of to a browser.

Also, this would be easy to implement to setup in cron by (assuming running once a second):

*/60 * * * * php myscript.php > /var/log/myscript.php.log 2>&1

Open in new window


The other option to avoid cron would be to create an engine in your script and have the script repeat itself.  It would still need to be started to kick off, but you could do this also via startup scripts, etc.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prileyosborneAuthor Commented:
insoftservice: Does this require me having my browser open to activate the refresh?  If not, can you kind of explain the function a bit so I understand how it works in case I need to adjust it a bit.

theodorejsalvo::
For that cron to work, how would I implement it?  It would have to be in a separate file on the server I assume, but how do I set it to run. This server doesn't use cpanel and I only have access to a single directory on it.

As for an engine and start up script, do you happen to have a link to any examples of these or any PHP functions that might be useful to accomplish these?  Thanks so much!

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

prileyosborneAuthor Commented:
Also, for a cron tab, if I have a file in my etc directory called crontab and it already has some cron calls, can I add this to that file and not ruin the other calls?

Thanks, sorry, total cron noob.
0
theodorejsalvoCommented:
Yes you can...and if you can, that is the easiest way.

If you don't have shell access, cron won't work.

Further questions:
Where is the JSON file that you are loading and checking, on the server?
What database is it sending changes to, the database on the server?
For file/database access, does the PHP script need to run on the server, or can you run it from an external machine?  In other words, can you access the file and database externally?
0
prileyosborneAuthor Commented:
Thanks for the quick feedback!  Here are the answers to your questions:

Where is the JSON file that you are loading and checking, on the server?
It is on the same server but using a different port.  (so 01.01.01.0101:1010 for example)

What database is it sending changes to, the database on the server?
Yes, it is a database hosted on the server. I am using the server ip to access it since the actual server it resides on has a lot of different partitions and frameworks on it.


For file/database access, does the PHP script need to run on the server, or can you run it from an external machine?  In other words, can you access the file and database externally?

I could probably run it locally and tunnel in using Putty or something, but I would prefer it resides on the server if possible.

Thank you so much and let me know if you need anything else!

0
InsoftserviceCommented:
did u tried my script.
just replace it with ur php page it will help u
0
prileyosborneAuthor Commented:
insoftservice,  will that script work outside of a browser?  I need to refresh this page even when I am not browsing to it. Thanks!

0
prileyosborneAuthor Commented:
For those keeping score, I had to use the crontab to refresh the script. I also was able to secure command line access wit putty through SSH, so I am able to use it.  So any suggestions would be great, but if not, I will probably close this topic since I was able to get the file to load every minute with a crontoab.

Thanks again!
0
InsoftserviceCommented:
yes.
0
prileyosborneAuthor Commented:
After I got command line access, this is how I set up my cron and am beginning to set up a daemon to run the file more often than every minute. Thanks for all the advice from everyone!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.