当php在网络驱动器上写入大字符串时,会放入垃圾或丢失部分

My php script needs to write text file, (actualy write php code), in order to include it on the next run. So I have all my data (arrays) from the previus run, with out the use of database. The files are saved on a network drive (SAN).

The script runs 3-4 times in a sec (approx every 300 milisecs) and the size of file is 1.2 MB (approx)

Some times the file are corrupted, with missing END OF FILE (EOF)

Some times I get junks of text (repetead part of string)

eg.

$write_string = '$arrMK[1][1]=1.80;$arrMK[1][2]=1.82;$arrMK[1][3]=2.14;$arrMK[1][4]=1.80;$arrMK[2][1]=2.43;$arrMK[2][2]=1.13;$arrMK[2][3]=1.33;$arrMK[2][4]=4.11;... and so on...';

and the content of file is like (bold is repeted part):

$arrMK[1][<strong>1]=1.80;$arrMK[1][2]</strong>=1.82;$arrMK[1][3]=2.14;$arrMK[1][4]=1.80;$arrMK[2][1]=2.43;$arrMK[2][2]=1.13;$ar<strong>1]=1.80;$arrMK[1][2]</strong>rMK[2][3]=1.33;$arrMK[2][4]=4.11;

If the file size is less than 1 MB, everything is OK.

I have try using fopen/fwrite, file_put_contents, with the same results. Any suggestion about that?

Elias

May be the PHP script cannot complete its write operation before your user requires it. Try to call fflush() and fclose() on your script to be sure that your file is closed correctly.

Remember to pay attention to PHP timeout/tuning issues that can prevent PHP to save the file correctly. Double remember to remove old files too, or your sysadmin will kill you sooner or later...

BTW, IMHO it's a very ugly way of doing. You can use sessions to save user states and environments (check for session_start)