Moein Hosseini
Moein Hosseini

Reputation: 4383

Cron Job with PHP or Python

I need cron job which fetch data from wsdl and store in database periodicly.How can I implement it in singleton to be sure no new instance created before latest ended?

I used file to store is cron job running or not,but I think better way should be exist.In java we can run Jar as daemon ,so it can controller to be singleton and never be kill(if killed,a new instance will created).How to implement it with out file in PHP or Python?

Upvotes: 2

Views: 638

Answers (1)

László Papp
László Papp

Reputation: 53155

You could use semaphores if you do not like the pid file lock, even though that is a common practice. Also, I would suggest using flock/fcntl instead of pid lock files. I think that would be quite good for you.

As for bash lock file practices right from the cron job, you could look at a good existing practice in here:

#!/bin/sh

lockfile="/tmp/cron_rsync.lock"
if [ -z "$flock" ] ; then
  lockopts="-w 0 $lockfile"
  exec env flock=1 flock $lockopts $0 "$@"
fi

Upvotes: 2

Related Questions