I don’t understand much about php, I had to log the results of js tests to a file. In general, here is a php script that writes logs from YUI tests to a file:

$serverTime = Date('YmdHis'); $logFile = "result/log".$serverTime.".html"; $logFileHandle = fopen($logFile, 'a'); $messageReceived = trim($_REQUEST["msg"]); fwrite($logFileHandle, $messageReceived."\r\n"); fclose($logFileHandle); 

During the test, this script creates several log files. I only need one for the duration of the test. How to do it right?

  • There is an idea to take time right at the beginning of the test via js and pass the ajax script to the file name via ajax. Apparently this is all due to the fact that I create a query for each test log. - Lucky
  • one
    not a bad idea) see answer Palmervan'a - thunder

1 answer 1

And how long does the test last? $serverTime = Date('YmdHis'); every second creates a file under the condition of every second access to the script!

Try this $serverTime = Date('Ymd'); will create a file for 1 day.

In addition, you need to write a condition

 if(file_exists($logFile)) { /*some actions*/ } 

Well, then the meaning.

  • one
    either $serverTime = Date('YmdH0000'); for hourly logs to be for example, probably it would be better ... in any case it depends on the “test” - thunder