problem with exec command

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
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

problem with exec command

Post by bg »

Im using the exec command to use image magick tools to create thumbnails (need something more robust than GD). PHP generates the command, which will work if I copy and paste the generated command and execute it from the terminal. However, it does NOT work when executed from the exec() function in PHP. The function itself returns nothing, and the third parameter which is the return value of the executed command returns 127. There is no cwd issue since i use a full path for the file names. There also shouldnt be any ownership issues since all the folders that these commands are being executed upon are owned by the web server.

PS - I am aware that there is the imagick pecl module, but it is buggy and causes php to act very strangely.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Not sure what you're problem is but just in case you dont know... exec() only returns the last line of the output....

EDIT: Hmmm... where did all the avatars go 8O :?
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

d11wtq wrote:Not sure what you're problem is but just in case you dont know... exec() only returns the last line of the output....

EDIT: Hmmm... where did all the avatars go 8O :?
you have the ability to see all output via the second parameter, regardess, no output.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code please.
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

feyd wrote:post your code please.

Code: Select all

function imagick_create_thumbnail($image_dir, $image_name, $max_width, $max_height){

        $cmd = 'convert ' . $image_dir.$image_name . ' -thumbnail ' . $max_width .'x'. $max_height . ' ' . $image_dir . 'thumb_' . $image_name;
        exec($cmd, $somevar, $retval);
        return ($retval == 0) ? true : false;
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's possible the function is returning before it really completed the command.. have you tried sleeping for a few seconds?


gd can perform the actions you have specified without much trouble.
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

gonna give gd a shot but now im running into a completely unrelated problem. Trying to compile the gd extension on php but for some reason it relies on x.org... no way am i gonna bother compiling that on a server system that only gets accessed via ssh. I guess ill have to play around with compiling GD to get rid of this stupid dependancy.
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

got GD working... gonna have to get caught up on it, never played with it before...
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

Post by bg »

ok, was getting the same php wierdness using the gd extension as I was the imagick extension. checked the error log and im getting memory allocation issues. Is there a directive in the php.ini that needs to be increased?

edit:

memory_limit seems like the only directive that would affect this, and its currently set to 8mb...

edit again: doubling this to 16meg fixed it :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=30239&highlight=memory+bytes

that should explain the issue..
Post Reply