Try using or look into flock();
What this does is, locks a file, a simple file, so, you can create a simple empty file and usa a condition to see if its locked or not, if is locked then terminate the process, if is not locked then continue with process.
try something like this:
$f = fopen('./tmp/lock.txt', 'w') or die ('path to file doesn't exist');
$lock = flock($f, LOCK_EX | LOCK_NB) or die ('lock.txt is locked, is being used');
echo "lock is free";
//continue with code here
if you are using this in a script that is being triggered by cron, be sure to use LOCK_NB, is you don´t use it, it will indicate to use the wait() command until lock.txt is unlocked.
take a look at this post
https://stackoverflow.com/a/10552054/15285033