st0bsel st0bsel - 3 months ago 8
Ajax Question

PHP script didn't show correct data on server shell

I want to run this script:

<?php
$file = file_get_contents('data.json');
echo ($file);
unset($file);
exit(0);
?>


If I access this over ajax in JS there are no problems, but if I run this script on my servers shell with
php script.php
or
php -f script.php
there is allways an older version of this JSON string shown. Over ajax I receive allways the newest data from this script.

Finally i need this script to be included in another php script which runs a loop for detecting changes. This also didn't receive the newest data.

Answer

Try this:

<?php
$file = file_get_contents( __DIR__ . DIRECTORY_SEPARATOR .'data.json');
echo ($file);
unset($file);
exit(0);
?>

data.json should be in the same directory as your php file.