0

I have two phps that do separate tasks and are executed using cronjobs. One executes every 5 mins and the other every 2 months. I want to make sure that when the 2 month php starts executing, the 5 min php isn't executing.

I want something like this,

PHP 1:

function execute1()
{
    //set value of static variable
    //do job
    //unset value of static variable
}

PHP 2:

function execute2()
{    
 //This is the part where I need help
    if (static_variable is set)  //keep on waiting til value is unset
    {
        //do job
    }
}

Should I use semaphores?

Zoran777
  • 564
  • 2
  • 7
  • 25
  • Can't you use the static variable (which doesn't need to be a static) outside the functions, and create the logic based on that? – Dan Costinel Feb 10 '17 at 08:43
  • These are separate phps, so I could use a global parameter or something. But the main issue is how to make the function execution wait until the value is reset by the other php? – Zoran777 Feb 10 '17 at 08:46
  • 1
    Maybe this question helps http://stackoverflow.com/q/39976805/1741542. You could also use a flag in a database. – Olaf Dietsche Feb 10 '17 at 08:47
  • @OlafDietsche - I have already seen this answer. But I still don't get how to pause the execution while the value is reset by the other php. And I have tried storing the flag in the db. But the problem with that is that if the 2 month php doesn't have the value as reset, it will stop executing further. How to execute it again when the value is reset? – Zoran777 Feb 10 '17 at 08:50
  • 1
    See http://php.net/manual/en/function.sem-acquire.php, the process acquiring the semaphore blocks until it is released by the other process. – Olaf Dietsche Feb 10 '17 at 08:54
  • @OlafDietsche Thanks! That's how I did it. Using sem_get, sem_acquire and sem_release. – Zoran777 Jun 21 '17 at 13:02

0 Answers0