开发者

Php - run another page and go

i've a question, in a php script开发者_如何学Python I've to do some things, and I need to be really fust, but in the script I've to do some database controlls, too, so, I would know if it's possible run an external php page, that do something, but without wait for its results. Thanks (P.S.: sorry for my english)


You'll want to look at using Javascript and Ajax. This allows you to run a php script from within a page asynchronously.

If you use a javascript library, such as jQuery then you can use something similar to this:

$.get('my_script.php', function(response) {
    // This code is ran when the page has been loaded
    // `response` is the content you get back from script
});

For more information have a look at the jQuery documentation on the $.get function.


You can use Ajax to do that, it let another script run in background.


Yes, you can use Ajax for this. Using Ajax you can run php code in the background, however if user navigates to another page, the execution of that php code will be terminated. The simplest way to get started with Ajax is to use a library like jQuery. See http://www.devirtuoso.com/2009/07/beginners-guide-to-using-ajax-with-jquery/

Hope this helps

--EDIT-- This how you can achieve calling exec(php script.php) using Ajax and PHP

home.php (here you are using Ajax to run exec.php)

<!--include the jQuery library -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.js"></script> 
<script type="text/javascript">
function runInBackground(){
   $.get('exec.php', function(data) {
  });
}
</script>

exec.php

<?php
 exec(php script.php);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜