system exec shell_exec passthru backtick ??????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jrlooney
Forum Newbie
Posts: 6
Joined: Wed Feb 06, 2008 1:25 pm

system exec shell_exec passthru backtick ??????

Post by jrlooney »

Ok, so here is what I am trying to do. I have this old Perl script which I cannot get rid of because it is part of a large content management system. It has an image uploader which currently uploads just about anything. I want to take advantage of OSX's "sips" command to resample the image and generate thumbnails. This is just a unix command, so I should be able to use one of the functions in the title above. However it doesn't work.

In Perl, there are also system() and bactick operators. So, in the Perl code, right after the image is uploaded, I add a call to a php script:

Code: Select all

`/usr/bin/php /Users/php/acuweb_helpers/create_thumb.php $path $thumb_path`;
$path is the path to the image
$thumb_path is where I want to write the thumbnail file to

Now, the php script looks like this:

Code: Select all

<?php
$path = $argv[1];
$thumb_path = $argv[2];
 
exec("/usr/bin/sips --resampleWidth 60 $path --out $thumb_path", $output, $ret);
 
$stuff = implode(',',$output)."\n";
$string = "/usr/bin/sips --resampleWidth 60 $path --out $thumb_path"." ,returns: ".$ret."\n\n";
$handle = fopen('/Users/php/acuweb_helpers/out.txt', 'a');
fwrite($handle, $string);
fwrite($handle, $stuff);
fclose($handle);
?>
All the extra stuff there is just me troubleshooting - I write to a text file, the command that I am passing to exec() so I can make sure it comes out right (which it does, everytime).

So, the problem is that the exec() fails. I have checked permissions and they are wide open. I even modifed the command to be like this (to try and force the command to be executed as root user):
sudo -u root -S /usr/bin/sips --resampleWidth 60 $path --out $thumb_path < /etc/root.secret
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: system exec shell_exec passthru backtick ??????

Post by Christopher »

You might want to check the php.ini configuration to see if where you can exec is sandboxed.
(#10850)
jrlooney
Forum Newbie
Posts: 6
Joined: Wed Feb 06, 2008 1:25 pm

Re: system exec shell_exec passthru backtick ??????

Post by jrlooney »

Here's the tricky thing. Since I am printing out to that file (just so I can see the full command being sent to exec()), I can take the string from that file, put it in a php script and it works just fine.

In other words, if you look at my code above, the command contains variables that need to be interpolated.

However if I just run this script, it works fine:

Code: Select all

<?php
 exec("/usr/bin/sips --resampleWidth 60 /Users/aw/www/images/uploads/1.jpg --out /Users/aw/www/images/uploads/thumbs/1.jpg", $output, $ret);
?>
So, apparently I am set to run exec w/o trouble. Note that I have also used the backtick operator and passthru on different occasions. Any other thoughts on ways to troubleshoot? For example, does anyone know the significance of the return error codes for exec()? When I run this it always returns a 6.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: system exec shell_exec passthru backtick ??????

Post by Christopher »

If you do this right before the exec() call, what does it print?

Code: Select all

echo "/usr/bin/sips --resampleWidth 60 $path --out $thumb_path";
(#10850)
jrlooney
Forum Newbie
Posts: 6
Joined: Wed Feb 06, 2008 1:25 pm

Re: system exec shell_exec passthru backtick ??????

Post by jrlooney »

Thank you for replying.

Good thought - that is why I had it printing everything to a file so I could see it. Here is what it echos:

Code: Select all

/usr/bin/sips --resampleWidth 60 /Users/aw/www/images/uploads/1.jpg --out /Users/aw/www/images/uploads/thumbs/1.jpg
which is correct.
jrlooney
Forum Newbie
Posts: 6
Joined: Wed Feb 06, 2008 1:25 pm

Re: system exec shell_exec passthru backtick ??????

Post by jrlooney »

nudging back to top :|
Post Reply