Ho il seguente codice PHP:
Codice PHP:
$domstatus=new DOMDocument();
$domchess=new DOMDocument();
$fpstatus=fopen("status.xml","r+");
$fpchess=fopen("chess.xml","r+");
if (flock($fpstatus,LOCK_EX)) {
$xmlstatus=fread($fpstatus,filesize("status.xml"));
$domstatus->loadXML($xmlstatus);
$rootstatus=$domstatus->documentElement;
if (($statusnodeengine=$rootstatus->getElementsByTagName("engine"))&&($statusnodeactive=$rootstatus->getElementsByTagName("active")))
if (($statusnodeengine->item(0)->nodeValue=="on")&&($statusnodeactive->item(0)->nodeValue=="off")) {
$statusnodeactive->item(0)->nodeValue="on";
$xmlstatus=$domstatus->saveXML();
fseek($fpstatus,0,SEEK_SET);
fwrite($fpstatus,$xmlstatus);
ftruncate($fpstatus,ftell($fpstatus));
if (flock($fpchess,LOCK_EX)) {
$xmlchess=fread($fpchess,filesize("chess.xml")); //fread non ritorna nulla
$domchess->loadXML($xmlchess);
$rootchess=$domchess->documentElement;
flock($fpchess,LOCK_UN);
} //if
$xmlstatus=fread($fpstatus,filesize("status.xml"));
$domstatus->loadXML($xmlstatus);
$rootstatus=$domstatus->documentElement;
$statusnodeactive=$rootstatus->getElementsByTagName("active");
$statusnodeactive->item(0)->nodeValue="off";
$xmlstatus=$domstatus->saveXML();
fseek($fpstatus,0,SEEK_SET);
fwrite($fpstatus,$xmlstatus);
ftruncate($fpstatus,ftell($fpstatus));
} //if
flock($fpstatus,LOCK_UN);
} //if
fclose($fpchess);
fclose($fpstatus);
Dopo l'esecuzione i file rimangono immutati (come deve essere) ma la fread() non restituisce nulla, nonostante il file non sia vuoto.
Come mai?