PHP will execute first, on the server, so you would have to code it in a .php file, to ensure the server runs it through PHP, then have it embed the PHP in the JavaScript like so:
<script>
function message(){
alert("<?= $phpMessage ?>");
location.href = "http://www.example.com" /* The URL you would like the user to go to next */;
}
setTimeout(message,3000);
</script>
Assuming you want to display a message from PHP, you may embed it in an alert statement as <?= $phpMessage ?>. This will be awkward for your users.
A more graceful solution would be to use session storage to pass a message to the next page.
On the page that is receiving the data and needs to send a message, the first PHP command, before any output is sent should be session_start(). A message may be saved in a session variable with $_SESSION['message'] and it will be available for the next script, like so:
one.php (first page)
<?php session_start(); $_SESSION['message'] = 'My Message';
two.php (second page)
<?php session_start(); echo $_SESSION['message']; unset($_SESSION['message']); ?>
Notice that the second script must use unset to clear the message.