在PHP中创建一个日志文件[重复]

This question already has an answer here:


So, I have an application in PHP that register users and items and then I can "give" an item to a user, and what I want it to create a log file that register the 'life cycle' of an item. eg:
I create an item and give that item to the user 'Mike', a few weeks later the user 'Mike' give back that item bc the item broked, and I want all that to be on a log file.
Any tips? Thanks!

</div>

For what it's worth MySQL provides the very efficient ARCHIVE storage engine, suitable for write-a-lot read-infrequently use patterns.

It's a good choice if you want your log data in the DBMS (backed up, etc).

It's also a good choice for log data when your web app runs on multiple servers: all the entries go to one place, and you don't have to wonder which machine a particular log entry lives on.

$fp = fopen('logfile.txt', 'a');
fwrite($fp, date("Your date format").'Item xy passed from User Mike to User Alice');
fclose($fp);

a indicates to open the file and point to the end (typical for log files). Then you just print a timestamp and write which Item was passed from which user to which user, and close the file again. Just execute this after your actual code.