Executing a process on my localhost via PHP - not working

Discussion in 'Mac Programming' started by toddburch, Sep 19, 2007.

  1. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #1
    I am trying to work out why some processes work when called from PHP on my localhost and why others will not work.

    In my PHP script, I have this:
    PHP:
    $last_line system("./mycprog"$result) ;   
    echo 
    "last_line = " $last_line "<br/>" 
    echo 
    "result = " $result 
    In mycprog.c, it does this: (literally - this is all it does)

    Code:
    #include <stdio.h>
    int main (int argc, const char * argv[]) {
        printf("Hello from Compiled C code!\n");
        return system("open -a \"sketchup 5\"") ; 
    }
    On my PHP page, when I click the associated button, I get on my page:

    Where does this RC=6 come from? Is this Apache? PHP?

    I've also tried in PHP:

    PHP:
    $result exec('open -a "sketchup 5"')  ;
    and it does not work either. RC=6.

    Running the C program standalone, it works fine.
    Running open from Terminal kicks off Sketchup just fine.
    Running open from a Ruby script, kicks off SketchUp just fine.

    I've tried system(), exec(), passthru() from PHP, and all give the same error.

    Thanks, Todd
     
  2. tyr2 macrumors 6502a

    tyr2

    Joined:
    May 6, 2006
    Location:
    Leeds, UK
    #2
    Are you exicuting the PHP via Apache and a web broswer or similar? I'm not sure if 'open' is ever going to work in that instance as Apache isn't running as the logged in user, not will it have the right 'environment' to be able to launch apps to the screen.

    I could certainly be wrong tho.
     
  3. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #3
    if the host has phpsuexec running, then apache processes do run as the user executing them (instead of 'nobody'). however, the host may have disabled from php some of the more dangerous system calls, like system() and exec().

    best to check with the host to see what they recommend/allow.
     
  4. toddburch thread starter macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #4
    I'm running Apache as a personal web server on my Mac Pro with Safari as the broswer. Tiger 10.4.10.

    So, in this case, I am the host. What question should I ask myself and where do I look to answer myself? :confused: :eek:
     
  5. savar macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #5
    This is kind of a weird thing you're developing. I think the others are correct. When finder executes an application it connects that application to the Window Server. That might not be happening when you run under PHP.

    1) Try modifying the PHP like this: $last_line = system("./mycprog 2>&1", $result) ;

    The 2>&1 will redirect error output to your PHP program so you can see any error messages your call to "open" might produce. You could also "tail -f" the system.log, which is stored in /var/log.

    If that doesn't work, then bring out the big guns:

    2) You know the C program is executing, so you might want to work on debugging there. Insert a while (1); statement to make the program infinite loop. At this point when you run the PHP it should hang. Attach gdb to the myprog instance and then step out of the loop and through the rest of the program.
     
  6. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #6
    1. email yourself a complete and well-written description of your setup, what you're trying to do, what results you're getting, and a list of concise questions to get to the root of the matter

    2. when you receive your email, email back a reply saying your email was received and it will be looked at "shortly"

    3. next monday, quote your entire original email and answer only the first question, but in such a way to indicate the question was not understood. then make some inquiries about your setup, ignoring the fact that they were supplied in the original email.

    4. once you receive your own support reply, shoot back an email expressing your frustration and threatening to take your business elsewhere

    5. suspend your account

    6. lobby a complaint against yourself with your credit card company

    :)
     
  7. toddburch thread starter macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #7
    Sounds about right zimv20.

    savar - thank you too. I've already tried redirection of stderr to stdout, but nothing is produced. Not familiar with tail - will "man" that to see what it is.

    The gdb tip sounds like it would probably be pretty telling... Will look into that as well. Thanks.

    Todd
     
  8. toddburch thread starter macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #8
    More diagnostics. I tried calling TextEdit instead of SketchUp, and I get the same RC=6. Grrr.

    Todd
     
  9. toddburch thread starter macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #9
    Issuing "tail /var/log/system.log" shows:

    Sep 23 13:54:07 todd-burchs-computer open: kCGErrorRangeCheck : Window Server communications from outside of session allowed for root and console user only

    Todd
     

Share This Page