php获取第一行文件并移动到文件的最后一行

时间:2015-01-27 17:21:21

标签: php

我有这个脚本:

<?php
date_default_timezone_set('Europe/Berlin');
$date = date('d/m/Y h:i', time());

$ip = getenv("REMOTE_ADDR");
echo read_and_delete_first_line('data.txt');

function read_and_delete_first_line($filename) {
  $file = file($filename);
  $output = $file[0];
  unset($file[0]);
  file_put_contents($filename, $file);

  $file1 = fopen($filename, "a");
  fputs ($file1, $output);
  fclose ($file1);

  return $output;
}

?>

这个获取第一行文件并移动到最后一个文件,问题是,如果同时收到更多请求,php从data.txt中删除所有数据并保存文件为空。如何解决这个问题?有可能使用这个方法还是需要使用mysql?

0 个答案:

没有答案