Running Commands from PHP

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
cj10111
Forum Newbie
Posts: 4
Joined: Fri Sep 09, 2005 10:03 am

Running Commands from PHP

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
cj10111
Forum Newbie
Posts: 4
Joined: Fri Sep 09, 2005 10:03 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
cj10111
Forum Newbie
Posts: 4
Joined: Fri Sep 09, 2005 10:03 am

Post 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.
cj10111
Forum Newbie
Posts: 4
Joined: Fri Sep 09, 2005 10:03 am

Post 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 :)
Post Reply