11

after full html page load want to execute some php api's & script and display response

<html>
<body>
content 
<?php
//some php script execute after full page load
?>
</body>
</html>
Prashant
  • 143
  • 1
  • 1
  • 7
  • possible duplicate of: https://stackoverflow.com/questions/23258088/can-php-run-after-the-page-is-loaded – Davide Alberani Oct 22 '17 at 08:13
  • Another way: [https://stackoverflow.com/questions/4236040/example-of-how-to-use-fastcgi-finish-request](https://stackoverflow.com/questions/4236040/example-of-how-to-use-fastcgi-finish-request) – John Dorner Jul 09 '19 at 21:19

2 Answers2

16

PHP is a server-side programming language. It gets executed when you request a page. So you cannot execute it after the page has been loaded. If you need to check if something has loaded on the client side, you'll have to use a client-side programming language like JavaScript.

That way you can make a request to a PHP file (which will be executed) and get process everything that is returned by the file.

You can do this using JavaScript or jQuery (a JavaScript library):

<script type="text/javascript" src="jquery.js"></script>          
<script type="text/javascript">
    // Check if the page has loaded completely                                         
    $(document).ready( function() { 
        $('#some_id').load('php-file.php'); 
    }); 
</script> 
Tom Udding
  • 2,264
  • 3
  • 20
  • 30
7

To do so you could make use of the Ajax calls after the page is rendered ,

$(window).load(function(){ /*This allows to execute your code after the  page is rendered fully */ 
    $.get("<path to php file>", function(data){
     /* you can then process the ajax response as needed */
    });
})

You can this (Javascript that executes after page load) ,to be helpful to load your script after page load

Naresh Kumar
  • 1,706
  • 1
  • 14
  • 26