The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

suPHP not creating background exec()

Discussion in 'General Discussion' started by EXT3FSCK, Apr 19, 2008.

  1. EXT3FSCK

    EXT3FSCK Member

    Joined:
    Apr 19, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    We recently upgraded all of our fleet to suPHP, and we have encountered a problem with alot of clipshare/vshare scripts out there.

    After alot of debugging it turns out its due to suPHP isn't allowing background processes from exec() , it does kinda, but it doesn't like it when the script is modified, like if variables passes through a script, as soon as those variables are gone from the script it was called from , the BG process dies immediately, so soon as the script calls it, and ends the variables, it dies, so it didn't give time to do the conversion or even placed the script in the background to run.

    I am stuck to what could be causing.

    Here is a quick way to reproduce the problem:

    Lets say you have a script named testbackground.php

    Inside I have:


    <?
    exec("/usr/bin/php /home/USERNAME/public_html/convert.php 331.avi 331 /home/USERNAME/public_html/video/331.avi > /dev/null &");
    ?>

    This properly works if I run it in the browser, it immediately gives me a whitepage, and using top -uUSERNAME I can see the background process working.

    But if you quickly edit the same script, testbackground.php , and comment the exec() line to:


    <?
    #exec("/usr/bin/php /home/USERNAME/public_html/convert.php 331.avi 331 /home/USERNAME/public_html/video/331.avi > /dev/null &");
    ?>

    As soon as you hit save, like via nano, etc, the background that was previously running, it immediately dies.

    I am stuck to what could be causing this.

    I pictured it was due to MTP from Apache2, but I disabled it, and still causes it.

    If anyone has any insight to what causes this, please let us know.

    Thanks.
     
  2. EXT3FSCK

    EXT3FSCK Member

    Joined:
    Apr 19, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Actually now that I look at it, the background process doesn't work when it does initiate, if you don't edit the variables, it just keeps looping calling itself back again, the testbackground.php script, cause when I see top -uUSERNAME

    I see php process, which supposedly is running in the background, keep changing pids, and soon as you edit the file not to exec , it stops completely, dies of.

    Hard to tell what is going on, if anyone can give any hindsight to this , would be great :)
     
  3. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,383
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Have you tried calling the script through nohup?

    PHP:
    <?
    exec("/usr/bin/nohup /usr/bin/php /home/USERNAME/public_html/convert.php 331.avi 331 /home/USERNAME/public_html/video/331.avi > /dev/null &");
    ?>
     
  4. EXT3FSCK

    EXT3FSCK Member

    Joined:
    Apr 19, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    I tried it, it shows the same behavior, I just can't explain how its causing it.

    Like somehow in the background it keeps calling testbackground.php , in the browser even if I look in the logs its only been called once when I do.

    In top -uUSERNAME, I see:


    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    8814 cleantub 25 0 35024 12m 5844 R 1 0.4 0:00.02 /usr/bin/php /home/USERNAME/public_html/convert.php 331.avi 331 /home/

    Where its actually trying to run it, and I see the command there like if its attempting to work, but the PID keeps changing, and running a quick strace on any PID that I could find above, seems to be calling testbackground.php over and over again, so that is why when I open testbackground.php and comment exec() , it stops showing up in top -uUSERNAME.

    I am puzzled why this behaviour is happening on suPHP.

    Anyone else using suPHP experience this same behavior?
     
  5. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,383
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    The issue probably has to do with the fact that the process is being called to run in the background without a controlling terminal.

    You might be better served to review how you are wanting to do this. Have the PHP script trigger a flag somewhere on your account, and set a crontab task to check for that flag at a certain interval and if its present, run this command. This would offer a much higher probability of success.
     
  6. EXT3FSCK

    EXT3FSCK Member

    Joined:
    Apr 19, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    It would be, yes, but this defeats the purpose on how this used to work before, and ClipShare scripts it would be a pain to ask the hundreds of customers we have for this application to rewrite their code for it to work.

    This should work in suPHP, I am just not seeing why its behavior is do erratic like this.

    Thanks.
     
  7. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,383
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    When you say that it used to work, when did it used to work? When you were using mod_php?
     
  8. EXT3FSCK

    EXT3FSCK Member

    Joined:
    Apr 19, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Correct, when PHP ran unsecure and free under user nobody :P
     
  9. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,383
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    It probably ran because mod_php runs inside of Apache's memory space. As long as Apache kept running mod_php would keep the script running. mod_suphp instantiates a new PHP process at each run, so running the script in this manner won't stay in memory.

    I really don't know if there is a solution to this with mod_suphp. You would likely have to modify the suPHP code. You might try discussing this with the users on the suPHP mailing list, but again I don't believe this will be possible without some major adjustments to the suPHP code.
     
Loading...

Share This Page