Solved

inexplicable PHP behaviour(!?)

Posted on 2008-06-12
8
174 Views
Last Modified: 2013-12-13
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...  


 

0
Comment
Question by:shallxrg
  • 5
  • 2
8 Comments
 
LVL 4

Expert Comment

by:afzz
ID: 21771543
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

0
 
LVL 9

Accepted Solution

by:
Rurne earned 125 total points
ID: 21771672
Where is 'mybin' saved at?  If you have anything like open_basedir or include_path in play and mybin is not in your DocumentRoot, you may simply not be able to see where the program is.
0
 

Author Closing Comment

by:shallxrg
ID: 31466614
thanks rurne... but see the comment i added for general view
cheers
roger
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:shallxrg
ID: 21776965
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!
0
 

Author Comment

by:shallxrg
ID: 21777165
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!
0
 

Author Comment

by:shallxrg
ID: 21778591
cancel that last post... i think i just got confused
0
 
LVL 9

Expert Comment

by:Rurne
ID: 21781039
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.
0
 

Author Comment

by:shallxrg
ID: 21785508
check.... thanks for the tip... i'll do that next i'm back in the office... today is saturday and SUNNY :-)
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question