php - It is correct to access same file from two different programs? -
so here goes, developing game can controlled via wi-fi, planning on modifying file via php webserver, file later read python program in constant loop detecting updates. @ given moment both python program , webserver open same file, there goes question...
this python code use:
file = open('file.ext', 'r') answer = file.readline() file.close() and php code:
$dir = $_post['dir']; $file = fopen('file.ext', 'w+'); switch ($dir) { case 'up': fwrite($archivo, 'up'); break; case 'down': fwrite($archivo, 'down'); break; case 'left': fwrite($archivo, 'left'); break; case 'right': fwrite($archivo, 'right'); break; } fclose($file); thanks!
avoid accessing file @ same time in 2 programs. because problems might occure. think in same time read , write.
kind of problems known "mutual exclusion" means resources (for example: file) must in access 1 program (or process).
so can use known solutions of mutual exclusion "semaphore" or "lock". see below links more information:
php mutual exclusion (mutex) php mutual exclusion on file / mysql reading , executing statements file using perl mutual exclusion thread locking, dropping of queued functions upon mutex/lock release, in python? http://wiki.bash-hackers.org/howto/mutex
Comments
Post a Comment