Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
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:

Hello from Compiled C code! last_line =
result = 6

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
 

tyr2

macrumors 6502a
May 6, 2006
832
234
Leeds, UK
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.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
Apache isn't running as the logged in user

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.
 

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
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:
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
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:

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.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
So, in this case, I am the host. What question should I ask myself and where do I look to answer myself? :confused: :eek:

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

:)
 

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
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
 

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.