Page 1 of 1

Running Commands from PHP

Posted: Fri Sep 09, 2005 10:12 am
by cj10111
I'm trying to make a PHP wrapper for webkit2png. webkit2png is a command line program for OS X takes a screenshot of a site with the Safari rendering engine.

The command to run webkit2png is:

Code: Select all

/usr/bin/python ./webkit2png-0.4.sh http://google.com --dir=./images/
This command creates three png files in the local images directory which I chmod'ed to 777.

In php I try:

Code: Select all

<?php

shell_exec('/usr/bin/python ./webkit2png-0.4.sh http://google.com --dir=./images/');

?>
When running the php file from the command line with:

Code: Select all

php screenshot.php
It works.

When calling the page from a web browser it does not work. I figure it has something to do with my Apache settings but I'm not sure where to look. Any ideas?

Thanks.

Posted: Fri Sep 09, 2005 10:16 am
by John Cartwright
I'm taking a stab in the dark but I think you have to pass appropriate image headers to display the image in a browser

Posted: Fri Sep 09, 2005 10:22 am
by cj10111
That not quite what it does. It simply writes three images to a specified directory. When running the script from the browser the files don't make it to the directory. When running it from the command line it does.

Displaying them in the browser will be the easy part. :D

Thanks.

Posted: Fri Sep 09, 2005 11:12 am
by feyd
I'm going to guess it's a permissions thing.. php will run as the user set under the web server, while you are running it as yourself (a different user very very likely)

Posted: Fri Sep 09, 2005 11:51 am
by cj10111
One would think that it would work if it was pointed at a directory in the local apache directory. I'll check my config again. Thanks for the replies. Any suggestions are welcome.

Posted: Fri Sep 09, 2005 1:27 pm
by cj10111
I figured it out. Apache was running PHP as user www under group www. I chown'ed the directory to that user and group and it worked.

Thanks :)