0

EDIT
I'm trying to run a php file in background without success using one of those function.
This is not the file that will be execute in backgorund (the real one will send emails), I use this method to find out which command parameter is the correct one
File permission 0644; Folder permission: 0755
tets.php:

<html>
    <head>
    </head>
    <body>
        <pre>
        <?php
            $ex='php5 -f /homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/run.php';
            exec($ex,$return);
            echo print_r($return,true);
        ?>
        </pre>
    </body>
</html>

run.php(works from url):

<html>
    <head>
    </head>
    <body>
        <pre>
        <?php
            $fp = fopen('/homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/data.txt', 'w+');
            fwrite($fp, '1');
            fclose($fp);
            echo 'printed';
        ?>
        </pre>
    </body>
</html>

these are my tries:

$ex='php5 -f /homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/run.php';

$ex='php -f /homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/run.php';

$ex='/usr/lib/php6 -f /homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/run.php';

Fisrt->

Array
    [89] =>     [79] =>     [69] =>     [59] =>     [49] =>     [39] =>     [29] =>     [19] =>     [9] => (
    [90] =>     [80] =>     [70] =>     [60] =>     [50] =>     [40] =>     [30] =>     [20] =>     [10] =>     [0] => X-Powered-By: PHP/5.2.17
    [91] =>     [81] =>     [71] =>     [61] =>     [51] =>     [41] =>     [31] =>     [21] =>     [11] =>     [1] => Content-type: text/html
    [92] =>     [82] =>     [72] =>     [62] =>     [52] =>     [42] =>     [32] =>     [22] =>     [12] =>     [2] =>
    [93] =>     [83] =>     [73] =>     [63] =>     [53] =>     [43] =>     [33] =>     [23] =>     [13] =>     [3] => 
    [94] =>     [84] =>     [74] =>     [64] =>     [54] =>     [44] =>     [34] =>     [24] =>     [14] =>     [4] =>  
    [95] =>     [85] =>     [75] =>     [65] =>     [55] =>     [45] =>     [35] =>     [25] =>     [15] =>     [5] =>  
    [96] =>     [86] =>     [76] =>     [66] =>     [56] =>     [46] =>     [36] =>     [26] =>     [16] =>     [6] =>  
    [97] =>     [87] =>     [77] =>     [67] =>     [57] =>     [47] =>     [37] =>     [27] =>     [17] =>     [7] =>      

    [98] =>     [88] =>     [78] =>     [68] =>     [58] =>     [48] =>     [38] =>     [28] =>     [18] =>     [8] =>      

    [99] =>     [89] =>     [79] =>     [69] =>     [59] =>     [49] =>     [39] =>     [29] =>     [19] =>     [9] => Warning:  exec() [function.exec]: Unable to fork [php5 -f /homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/run.php] in /homepages/23/d293813614/htdocs/amazonmobilewebsites/extendedcomingsoon/admin/test.php on line 8

    [100] =>     [90] =>     [80] =>     [70] =>     [60] =>     [50] =>     [40] =>     [30] =>     [20] =>     [10] => Array
    [101] =>     [91] =>     [81] =>     [71] =>     [61] =>     [51] =>     [41] =>     [31] =>     [21] =>     [11] => (
    [102] =>     [92] =>     [82] =>     [72] =>     [62] =>     [52] =>     [42] =>     [32] =>     [22] =>     [12] => )
    [103] =>     [93] =>     [83] =>     [73] =>     [63] =>     [53] =>     [43] =>     [33] =>     [23] =>     [13] =>        


    [104] =>     [94] =>     [84] =>     [74] =>     [64] =>     [54] =>     [44] =>     [34] =>     [24] =>     [14] =>    
    [105] =>     [95] =>     [85] =>     [75] =>     [65] =>     [55] =>     [45] =>     [35] =>     [25] =>     [15] => 
    [106] =>     [96] =>     [86] =>     [76] =>     [66] =>     [56] =>     [46] =>     [36] =>     [26] => )

the second the same array without the warning and the third is an empty array

Razorphyn
  • 1,314
  • 13
  • 37

1 Answers1

0

It's probably disabled on your host, but php itself isn't, so why don't you just include the file?

If your php is going to take a long time to run you can do the following:

ignore_user_abort(true);
set_time_limit(0);

your_long_function();

This will mean your script keeps running indefinitely (you can leave the page), which is potentially a dangerous thing to do. Be careful not to make any infinite loops.

ignore_user_abort
set_time_limit

See this answer for some other options too.

Community
  • 1
  • 1
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • This is not the file that will be execute in backgorund (the real one will send emails), I use this method to find out which command parameter is the correct one – Razorphyn Nov 23 '13 at 10:54
  • Yes, but if need to send 2000 emails it will take a lot of time and I have to wait untill the process is over – Razorphyn Nov 23 '13 at 11:11
  • @Dheed I've added another option – Tom Fenech Nov 23 '13 at 11:28
  • Does it work even from a an ajax call? Because this is the sequence: user write mail -> send ajax request to function.php -> function php put a process sendmail.php in background. How should I behave? – Razorphyn Nov 23 '13 at 11:34