shallxrg
asked on
inexplicable PHP behaviour(!?)
i have a snippit of PHP code which refuses to do the biz and i cannot for the life of me see why...
there is a simple (bespoke) binary ('mybin') which has 755 permissions and which maps an input string to stdout, eg: % echo "my_string" | mybin > outfile ... which works fine as a shell cmd...
now in my php script i coded both:
exec("echo $string_var | mybin > outfile");
and
exec("cat text.file | mybin > outfile");
... but each of these produce empty output files... i have plenty other 'exec's in my script which are fine... the darn' thing just seems to want to ignore 'mybin' (which was built on the host m/c)... i even tried restarting the apache httpds... ...no comprendo...
there is a simple (bespoke) binary ('mybin') which has 755 permissions and which maps an input string to stdout, eg: % echo "my_string" | mybin > outfile ... which works fine as a shell cmd...
now in my php script i coded both:
exec("echo $string_var | mybin > outfile");
and
exec("cat text.file | mybin > outfile");
... but each of these produce empty output files... i have plenty other 'exec's in my script which are fine... the darn' thing just seems to want to ignore 'mybin' (which was built on the host m/c)... i even tried restarting the apache httpds... ...no comprendo...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks rurne... but see the comment i added for general view
cheers
roger
cheers
roger
ASKER
rurne's solution was 'correct'... i moved 'mybin' from '/bin' to the docroot directory, and bingo... however, i cannot understand why the shell() and backtick commands can cheerfully invoke other executable binaries from /bin (eg gunzip) and yet not the bespoke binary 'mybin' .... permissions were ok ... still don't understand!
ASKER
this is quite possibly a nugget of info... i just discovered that the PHP shell() command WILL run my executable from /bin but ONLY if the binary is stripped(!!?!!)... (it will run it from the docroot directory whether or not it is stripped)
i simply did : strip -s '/bin/mybin' and off she went....
WEIRD!
i simply did : strip -s '/bin/mybin' and off she went....
WEIRD!
ASKER
cancel that last post... i think i just got confused
I'd highly recommend checking your Apache configuration for any open_basedir or include_path directives. Alternatively, you could be running in safe mode, which is not recommended (and deprecated in current versions of PHP for its bugginess). That would be why you could access something from the command line and not from CGI or ISAPI mode.
HTH.
HTH.
ASKER
check.... thanks for the tip... i'll do that next i'm back in the office... today is saturday and SUNNY :-)
Open in new window