Results 1 to 8 of 8

Thread: [RESOLVED] PHP Exec Not running, but command works ok!

  1. #1

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Resolved [RESOLVED] PHP Exec Not running, but command works ok!

    I have the following script to take an uploaded PDF in PHP and call ImageMagik/Ghostscript to convert to images of specified size.

    Code:
    $tmp = exec("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"", $results);
    However, this doesnt seem to work. No errors in the log file and no errors on screen. If I do the following,

    Code:
    $tmp = exec("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"", $results); 
    echo ("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"");
    And I paste the output into a command prompt it works fine (It takes around 6-10 seconds - My max_execution_time is at 600.

    Any suggestions on why this might not be working?

    This is Windows, IIS 7 and PHP5.

    Edit: I'm having the same issue in both CentOS and Windows. Both have ImageMagik and Ghostscript installed.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Exec Not running, but command works ok!

    can you make sure that the user running IIS (or Apache on CentOS) has the authority to execute those commands?

  3. #3

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: PHP Exec Not running, but command works ok!

    Quote Originally Posted by kows View Post
    can you make sure that the user running IIS (or Apache on CentOS) has the authority to execute those commands?
    Ok I'm not amazing with linux stuff, can you run through how I would go about doing that in CentOs?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP Exec Not running, but command works ok!

    Use the stat command on the input file and/or the directory where the output file will be written.
    Look at the owner setting and the permissions set.
    You can use exec('whoami') to find out what user your script is running as.

    Also, try trapping the return code from the exec command. Pass a variable into the third parameter and then read that after exec returns.

  5. #5

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: PHP Exec Not running, but command works ok!

    Still cant resolve this, the third param comes back as "1". Is there anything else I can do to Debug this?

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Exec Not running, but command works ok!

    this comment seems helpful for running exec() on Windows, but I'm not sure of the problem for your CentOS install.

    the last time I had issues using exec(), I was trying to auto-extract RAR archives using WinRAR. I ended up fixing it, but I'll see if I can't reproduce the problem and give you a solution for at least the Windows side of things. I do have a server running CentOS, so I could look for and see if I run into the problem with ImageMagik or WinRAR on that machine, and let you know what I run into. I can't promise this will be tonight, though!

  7. #7
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP Exec Not running, but command works ok!

    Hi.

    I took my time getting back to you! Anyway, I didn't realize ImageMagick was installed on most Unix systems already, so I ran the following to test via the console:

    Code:
    convert logo.png -resize 120x60 small.png
    and it worked fine. Then, I ran the following using PHP 5.3.3 on Apache 2.2.16:

    PHP Code:
    <?php

      exec
    ("convert logo.png -resize 60x30 small.png");

    ?>
    My guess would still be user permissions, I suppose. I'm using a web hosting account with WebFaction, where I don't have a caged shell (whereas most web hosts do limit what you can do via SSH). I also ran the script above using WebFaction's shared install of Apache/PHP5.2 after I had success with my custom install of Apache/PHP5.3, and the results were the same. The directory that the script was running from was chmodded to 755.

  8. #8

    Thread Starter
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: PHP Exec Not running, but command works ok!

    Yea it was a permissions issue, but not somthing that I can work out how I fixed. I have it working well on the CentOS box but windows is still failing. Not a big issue though as CentOS was the main one.

    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width