PDA

View Full Version : Executing php script every 30 seconds?


bzcomputers
06-01-2013, 04:40 PM
I currently have the following code in in a custom page which works fine executing a php script.

exec('php -q /path/to/file/getImage.php');
The php that is being executed saves an image to the server.


What I'm trying to do is get this to execute every 30 seconds while the page is loaded.


I've tried something like this, but it wouldn't work.


<script type="text/javascript">
jQuery(document).ready(function() {

setInterval(function() {
jQuery.get('/path/to/file/getImage.php');
}, 30000);
});
</script>

snakes1100
06-01-2013, 05:29 PM
Add it to a cron

0,30 * * * * /path/to/php /path/to/file/getImage.php

kh99
06-01-2013, 05:29 PM
It depends on how your server is configured, but the path to the file that you'd use in the exec command usually isn't the same as what you'd use while requesting it via http (which is what a jquery get() does).

I don't understand why in the first code you posted you're using exec(), but in the javascript you're calling getImage.php directly (I'm not saying it's wrong, I'm just curious).

ETA:...or use cron like snakes says above. :)

snakes1100
06-01-2013, 05:32 PM
looks like i beat by sec's lol

bzcomputers
06-01-2013, 07:49 PM
Edit:
......original code ended up working, the issue was the php I was trying to call was outside the public root and it wouldn't execute from the vB template from there (but it would from the main .php). Moved the php into a public directory and it worked.