Link to home
Start Free TrialLog in
Avatar of prileyosborne
prileyosborne

asked on

[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!
Avatar of Insoftservice inso
Insoftservice inso
Flag of India image

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>
ASKER CERTIFIED SOLUTION
Avatar of theodorejsalvo
theodorejsalvo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prileyosborne
prileyosborne

ASKER

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!

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.
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?
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!

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

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!
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!