在php文件上保存变量

I'm trying to save variables on php files. But every time a new input is entered the variable is overwritten and not incremented.

<?php
$var = 1000;
$file = "40.txt";
$content = serialize($var);
file_put_contents($file, $content);
$content = unserialize(file_get_contents($file));
?>

My question is, how to increment $var by 500 or any value each time page is reloaded without $var being reset to its original value. So the file (40.txt) will have hold a value that will be incremented every time the page is refreshed or opened.

Any help is appreciated.

$file = "40.txt";
$current = unserialize(file_get_contents($file));
file_put_contents($file, $current + 500);

If you are only using numbers, you don't need to serialize and unserialize every time.