fixed logic, added php file lock and removed unnecessary disk access