How do i use the await event in php echo

I have a script that echoes to a location at the end of a mysql query. I need to set a time before the function executes and found that the javascript event is 'await. I have tried in my code, but all I get is 500 error. Can someone please help with this. Thanks

echo "<script language=\"JavaScript\">\n"; 
echo 'alert("SUCCESS. You will now be redirected to the boxes requests area.");'; 
echo 'await sleep(4000)';
echo 'location.href = "boxdest.php"'; 
echo "</script>";

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mukesh YadavFull Stack DeveloperCommented:
For this in JavaScript we have setTimeout function:

echo "<script language=\"JavaScript\">\n"; 
echo 'alert("SUCCESS. You will now be redirected to the boxes requests area.");'; 
echo 'setTimeout(function(){ location.href = "boxdest.php" }, 4000)';
echo "</script>";

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
I don't think Await does not do what you think it does.
Firstly this is still in draft - part of ES2017 - so it is not guaranteed to be available
Secondly it is supposed to be used in async functions waiting the resolution of a promise.

What you should be using is setTimetout

setTimeout(function() {
   location.href = "boxdest.php";
}, 4000)

Open in new window

Or alternatively outputing a meta-refresh tag in the header
<meta http-equiv="refresh" content="4;URL='boxdest.php'" />

Open in new window

peter-cooperAuthor Commented:
Thanks for the help
Mukesh YadavFull Stack DeveloperCommented:
You are welcome! :)
Ray PaseurCommented:
The corresponding functions in PHP are - for long delays - for short delays
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.