0

current.php is page which we open in browser.

other_1.php and other_2.php are pages, which we want to execute. These two pages do a big job and work slowly.

How can we call both other pages to work, just when we open current.php?

current.php should just open and die, nothing get, just send commands to open.

If current page will include other pages, it will eat a lot of memory and go out from the maximum time execution available on hosting-account.

All the pages placed in same folder.

Any idea?

Thanks.

James
  • 42,081
  • 53
  • 136
  • 161
  • 1
    If either of those files uses sessions, be careful to `session_write_close()` in both of them before doing the long duration work. PHP's standard file-based sessions lock the session file upon `session_start()` and will not release it until you close the session or the script ends. That would mean only the first of the pages hit would run, and the other would wait until the first terminates/completes. – Marc B Aug 11 '10 at 12:52

2 Answers2

1

you can try this one:

function execInBackground($cmd) {
    if (substr(php_uname(), 0, 7) == "Windows"){
        pclose(popen("start /B ". $cmd, "r")); 
    }
    else {
        exec($cmd . " > /dev/null &");  
    }
}

In the $cmd you pass the path to php and than you can use the command as in CLI.

VeeWee
  • 560
  • 1
  • 5
  • 19
  • It executes a command (or a process) like when typing something into bash or cmd, but this function can be disabled on your web server due to security restrictions. – Emiswelt Aug 11 '10 at 12:16
  • 1
    normally it is, unless it's disabled. You can check this like: function exec_enabled() { $disabled = explode(', ', ini_get('disable_functions')); return !in_array('exec', $disabled); } $cmd can look like: /usr/bin/php -f /home/file.php – VeeWee Aug 11 '10 at 12:56
0

You can use

<?php

include("other_1.php");

?>

and at the end of other_1.php add another include for other_2.php, and so on. If I have misunderstood the question, let me know.

Liam Spencer
  • 936
  • 1
  • 11
  • 25
  • >If current page will include other pages, it will eat a lot of memory and go out from the maximum time execution available on hosting-account. – James Aug 11 '10 at 11:13