Link to home
Start Free TrialLog in
Avatar of shallxrg
shallxrgFlag for United Kingdom of Great Britain and Northern Ireland

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...  


 

Avatar of afzz
afzz

Instead of exec try the following if it works. Also try putting the full path to echo & cat like /bin/cat
`echo $string_var | mybin > outfile`;
`cat text.file | mybin > outfile`;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rurne
Rurne
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shallxrg

ASKER

thanks rurne... but see the comment i added for general view
cheers
roger
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!
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!
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.
check.... thanks for the tip... i'll do that next i'm back in the office... today is saturday and SUNNY :-)