What are the advantages and disadvantages of using a file-based approach versus a database approach for storing counter data in PHP?

When storing counter data in PHP, using a file-based approach can be simpler and more lightweight, as it involves writing and reading data directly to and from a file. However, this approach may not be as efficient for large amounts of data or concurrent access. On the other hand, using a database approach can provide better performance and scalability, but it may require more setup and maintenance.

// File-based approach
$counterFile = 'counter.txt';

// Read current count from file
$currentCount = file_get_contents($counterFile);

// Increment count
$currentCount++;
file_put_contents($counterFile, $currentCount);

echo "Counter: $currentCount";