Thursday, April 14, 2011

Cron but not frequent enough?

If you ever need a on going php process, lets say every 5 or 2 seconds once, you may use python script to do this.
Here is an example of a script:
--------------------
#!/usr/bin/env python
import thread
import time
import os
import sys

sPHPPath = "/usr/bin/php"

def myphp1():
  while 1:
    os.system(sPHPPath + " " + sys.path[0] + "/myphp1.php")
    time.sleep(2)

def myphp2():
  while 1:
    os.system(sPHPPath + " " + sys.path[0] + "/myphp2.php")
    time.sleep(2)

if __name__=="__main__":
  thread.start_new_thread(myphp1, ())
  thread.start_new_thread(myphp2, ())
  while 1:
    time.sleep(60)


No comments: