Search code examples
javaphpcron

Easiest way to hit a URL every x minutes


My plan is to hit an url (GET - rest) (ex: http://myserver.com/job ) every x minutes, I want to use something that could be free on the long run like a small programm running on heroku cloud.

Can I build something like that in php or java ? (both languages are supported on heroku and I have some familiarity with both)

I've tried in java so far but I don't think the multi-threading nature of it works because it gives me an error if I make any "request" logic inside a loop.

Sorry to ask such a broad question but from my search I havent found any good ideas for this problem.


Solution

  • SHORT ANSWER: Use IFRAME for your URL and in Javascript use setTimeout() to iterate.

    DETAILED ANSWER: Modify the following source as per your needs.

    (!!! https://www.disney.com is ok but some URLs may not accept IFRAME requests.)

    IN .HTML / .JSP:

      <head>
          <script charset="UTF-8" type="text/javascript" url="init.js"/>
      </head>
    
      <body onload="init()">
          <form id="form1">
             <iframe id="w_iframe" src="https://www.disney.com" style="left: 0px; top: 0px; width: 100%; height: 100%; position: absolute">
               <p>Your browser does not support iframes.</p>
             </iframe>
          </form>
      </body>
    

    init.js:

     function init() {
        var w_src = "https://www.disney.com";
        document.getElementById("w_iframe").src = w_src;
    
        setTimeout("init()", 60000);    //60,000 milliseconds
     }