5

Situation:
My php/html page retrieves the contents of another page on a different domain every 5-10 minutes or so.  I use a JavaScript setInterval() and a jquery .load() to request content from the other domain into an element on my page. Each time it retrieves content, javascript compares new content with the previous content and then I make an Ajax call to a php script that sends me an email of what the changes are.

Problem:
It's all working fine and dandy except for the fact that I need a browser constantly open, requesting the updates.

Question:
Is there a way to accomplish this with some sort of 'self executing' script on the server? Something that I would only have to start once, and it continues to run on it's own without needing a browser to be open as long as I want the script to run?

Thanks in advance! P.S. I'm not a php/javascript expert by any means, but I can get my way around.

5
  • 1
    If you have root access to your host (server or VPS) or cron permissions, you can use a cron job to run this every X minutes. Commented May 7, 2013 at 16:32
  • just use cron jobs on your server.. see this ~> nbill.co.uk/documentation/setting-up-a-cronjob.html Commented May 7, 2013 at 16:32
  • You can set a cron job to start your PHP script on the server. Commented May 7, 2013 at 16:32
  • 1
    php can be executed on the server quite easily via cron. Javascript cannot. Commented May 7, 2013 at 16:33
  • 1
    Thank you, cron job was the answer. I didn't know about these until now :) Commented Sep 6, 2014 at 4:34

3 Answers 3

1

I believe the thing you are looking for is a cron job.

Sign up to request clarification or add additional context in comments.

2 Comments

"javascript compares new content with the previous content and then I make an Ajax call..." Can you elaborate on how this is accomplished via a cron job?
You don't. You just have to create one PHP file that does everything and then set a cron job to execute it.
1

If your script relies on Javascript for proper execution, you will need to use a browser to accomplish your goals.

However, if you can alter your script to perform all of the functionality via PHP, perhaps using cURL to request the necessary data, you can use a cron job to execute the script at regular intervals.

Comments

1

If you're running a script at an interval, I would recommend using a bash script instead that runs in the background.

#!/bin/bash

while [ 1 ]
do
    php "script.php"
    sleep 300
done

Then you can run the script like nohup bash.sh. 300 seconds = 5 minutes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.