Link to home
Start Free TrialLog in
Avatar of kalis183
kalis183

asked on

Execute a PHP script every 2 mins

SCENARIO....
Currently I have this process setup on two servers.
A client uploads a PDF to server1(unix).
Server1 then sends the file to server2(windows).
Using purchased software the file is then converted into an HTML file(software only works on windows)

THIS IS WHERE THE SCRIPT COMES IN....
currently I have a script which checks for converted files on server2.
The files are then transferred back to server1 for viewing.

the script resides on server1, and it is executed by server2 using a browser with a 2 min refresh... although this seems to work okay I was wondering if there is a better way of doing this.  I have thought about CRON but I am not sure I can execute it every 2 mins.

thank you for your help
Avatar of rockmansattic
rockmansattic

Sounds inefficent, but I guess you could a batch file or scheduled task to do the job?  

I assume that server two is the only machine that needs to see the new file?
So you have a Meta refresh on the page?  You could also use javascript refresh, but since it works and it is soley for server 2 and no the public, meta is OK.

Other than that, dont know
ASKER CERTIFIED SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France 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
I didn't really say what this actually does: it checks for newly uploaded files every 2 minutes. If it finds any then it transfers them, taking as long as it needs to do so. When it's finished transferring, it will check again, and if it doesn't find any, it will sleep for 2 minutes.

To launch it, just run php daemon.php from a command line and it will create a new process that will stay running in the background. When it starts it will print a PID number, so to stop it, you'd need to enter kill -TERM <PID>.

Beyond this script, you could adapt your upload script so that when an upload completes it could send the daemon a SIGHUP (it can get the PID to send to from the saved PID file), which you could cause to trigger an immediate check. This would make your system even more reponsive, and remove the need for polling at all. Isn't UN*X a wonderful thing?
Avatar of kalis183

ASKER

Thanks Squinky!
I will try your solution
and award the points

cheers




Did this work for you?
Thanks Squinky, yes it did
sorry I got tied up with another project.

cheers