0

Say I start a PHP script via command line.

Is there a way that PHP can restart/rerun the script from the top via a command inside the PHP script?

<?php
if($something == 'yes')
{
 // restart/rerun whole PHP script
}
?>
4
  • Do you mean a loop? Commented Sep 25, 2019 at 12:07
  • Hi, no not a loop. I would like to force restart/rerun the entire script. Commented Sep 25, 2019 at 12:10
  • @Mr.Boon Put all these inside a function and call the function again. Commented Sep 25, 2019 at 12:18
  • Possible duplicate of Execute a PHP script from another PHP script Commented Sep 25, 2019 at 12:22

1 Answer 1

0

As told in comment you can send header. or if you in the middle of page, you can add <script> tag with window.location.reload() there

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, this is a PHP only script, no HTML/JS. Only runs via cron in commandline
Then advice of @Mr.Boon. Script with variable needReload = false then all script in function. In case of success do nothing. If you need reload then needReload = true and return. In main script call function again in loop if true. But beware of endless cycle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.