Этого можно добиться, ведя счетчик в файле txt
.Создайте каталог (счетчик имен согласно моему примеру) и пустой файл c.txt перед запуском этого процесса.Мы можем проверить, если файл не существует, а затем создать файл.Но в вашем случае он, кажется, вызывается чаще, поэтому здесь можно избежать дополнительной обработки.
Вот фрагмент кода,
// File where counter will be maintained. Change the path to the one desired
$filename = "/root/Desktop/counter/c.txt";
$handle = fopen($filename, "r"); // Open the file in read mode
$counter = fread($handle, filesize($filename)); //Read the file
fclose($handle); // Close file object
// Increment the counter if available else set it to 1
$count = !empty($counter) ? (int)$counter+1 : 1;
$homepage = file_get_contents("http://www.example.com/page=$count");
echo $homepage;
$handle = fopen($filename, "w"); // Open the file in write truncate mode
fwrite($handle, $count); // Store the counter in the file
fclose($handle); // Close file object