What are some alternative methods to using MySQL for creating a counter in PHP?

Using MySQL for creating a counter in PHP can be resource-intensive and may not be necessary for simple counting tasks. One alternative method is to store the counter value in a text file and update it as needed. This can be a more lightweight solution for small-scale projects.

// Read the current counter value from a text file
$counterFile = 'counter.txt';
$counterValue = (int) file_get_contents($counterFile);

// Increment the counter value
$counterValue++;

// Write the updated counter value back to the text file
file_put_contents($counterFile, $counterValue);

// Display the updated counter value
echo "Counter: " . $counterValue;