Run a PHP script in the background ... What are the best solutions for my business?

I am working on an email system that I must connect to the CMS for the company. I am looking for a way to get the email sender script to run in the background, when the administrator can move around or even close browsers.

I found a PHP function with the name ignore_user_abort()that is required for the page to work, even if it has a timeout.

Now I have three solutions for "running the script":

  • I could use iframe

  • I could use the Ajax call that I previously set to timeout very early. For example: using jQuery framework :$.ajaxSetup({ timeout: 1000 });

  • I could use the cron job, but I would like to avoid this solution, as they are "virtual" and unstable on this server.

Are there any other solutions? I really don't like the iframe solution, but I already use them with the Ajax script loader.

I do not want the administrator to hit F5 and start the second instance.

Company users were only asked to log into the CMS using Firefox. Thanks you

+3
source share
3 answers

You can run a PHP script in the background using Exec().

php docs give an example of how you can do this:

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

, . HTTP- script , 30 , , .

, .


cron (.. ), .

AJAX, PHP Javascript. Javascript-, , PHP 5 , , . Javascript , .

, , , - , .

0

, , script, php, . , , :

  • POST , , - , script , . , .. POST javascript, , , script. , script .

  • POST script, , , , . , -, -.

  • Cron ( , , )

0

Source: https://habr.com/ru/post/1774550/


All Articles