I relied on row locking in mysql to prevent simultaneous running of one php script when working on one userid.
I used following
UPDATE users SET rowlock = 1 WHERE id = ? AND rowlock = 0
and then in php
if($stmt->affected_rows == 0)
Ideally, if one instance of php script updates the rowlock to 1 then the second instance will not be able to update. second php script instance will have affected rows as 0 and it won't be possible to run same script twice on one userid.
However to my surprise if two scripts are ran at the same time then both are able to have affected rows as 1.