Page 1 of 1

System() and Exec() Not Working?

Posted: Tue Nov 09, 2010 7:55 pm
by Vik
When executed from the terminal, the following command works perfectly:

gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp'

However, when I run it from inside PHP with:

exec("gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp'");

...or:

system("gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp'");

...nothing seems to happen. How can I correct this?

Note - exec is enabled on my system, according to the following function:

function exec_enabled() {
$disabled = explode(', ', ini_get('disable_functions'));
return !in_array('exec', $disabled);
}

Thanks very much in advance to all for any info.

Re: System() and Exec() Not Working?

Posted: Tue Nov 09, 2010 8:05 pm
by Doug G
There are many possible reasons for the failure, probably all permissions related in one way or another. Start by reviewing the server logs for any error messages that help you identify the problem. Maybe your server php has an open_basedir restriction, more likely the web server user doesn't have permission to run the script.

Re: System() and Exec() Not Working?

Posted: Tue Nov 09, 2010 10:21 pm
by Vik
I am running Apache via MAMP, a local amp stack running on my development system on my iMac. I am running MAMP and the Terminal in my own user account. Will Apache have different permissions for accessing files on the disk, than I have when I am running a command via the Terminal?

Re: System() and Exec() Not Working?

Posted: Wed Nov 10, 2010 1:43 am
by VladSun
Vik wrote:Will Apache have different permissions for accessing files on the disk, than I have when I am running a command via the Terminal?
Yes.

Try debugging it:

Code: Select all

echo exec("gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp' 2>&1");
Also, always use absolute paths, including the command itself (i.e. gnuplot in this case)

Re: System() and Exec() Not Working?

Posted: Wed Nov 10, 2010 12:38 pm
by Vik
That solved it! Using the exec command per your sample code revealed the error "sh: gnuplot: command not found". Providing full path to gnuplot, (on my system, "/usr/local/bin/gnuplot"), then fixed that. It's working now. I really appreciate your help. Thanks very much!