Race Condition

A Race Condition is a broad term for any situation where the outcome of a program depends on the timing of uncontrollable events.

Race conditions happen in file systems, database accesses, sessions, cache, global variables, signals.

Race conditions may be migitated by using atomic operations, transactions, locks and unique identifiers.

<?php

    if (!file_exists('/path/to/directory')) {
        // race condition
        mkdir('/path/to/directory', 0755); // This might fail as the directory may be created between the time of the previous check and now
    }

?>

Documentation

See also PHP Race Condition Vulnerability Example, PHP MySQLi - Race condition 🏁 and Symfony Lock + Workflow: Taming the Race Condition that will hit you in production.

Related : Atomic Operation, Unique Identifier, Lock, Transaction, Session, Security, Time Of Check To Time Of Use (TOCTOU)