Jump to content


Photo

exec() / system() problem


  • Please log in to reply
7 replies to this topic

#1 ciocan

ciocan
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 July 2006 - 11:22 AM

Hi, I have a exec/system problem.
I want to execute a php script in background.
I tested with exec("php script.php > /dev/null 2>&1 &")
On my server works fine (i use cPanel) but on other
server that have directadmin this not works.
When i try echo exec("php -v") i get only a 127 return
and no php version text.

I compared the results from phpinfo() and I did not find
something to change to make it works.

When i try: system("whereis php",$out);echo $out;
on the good server i get:
php: /usr/bin/php /etc/php.d /etc/php.ini /usr/lib/php /usr/lib/php.ini /usr/local/bin/php /usr/local/lib/php /usr/local/lib/php.ini /usr/include/php /usr/man/man1/php.1 0

and the server where is not working:
php: /usr/local/man/man1/php.1 0

In my phpinfo() on the server that works I don't see CLI extension
enabled. (if this is the problem)

Which settings do I have to change to make this works ?

Thanks

Radu
PS: safe_mode is off on both servers

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 July 2006 - 01:52 PM

Are the OSes the same?

What does exec('php -v; echo $?'); give you? How about something as simple as exec('ls');?

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 ciocan

ciocan
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 July 2006 - 02:04 PM

The first server which works is
Linux 2.6.9-022stab078.9-enterprise #1 SMP Thu Jun 8 12:38:51 MSD 2006 i686

and the second one which i have issues is
FreeBSD 4.10-RELEASE-p3 FreeBSD 4.10-RELEASE-p3 #0: Wed i386

I executed exec('php -v; echo $?'); and i get 127 0 as response;
exec('ls'); works fine, it returns the files there.

Radu

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 July 2006 - 02:26 PM

You might want to check your settings again. The following code gives me "1":

<?php
	exec('php -v', $output, $return_val);
	echo $return_val;
?>

Also, do you know the full path to the php executable?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 ciocan

ciocan
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 July 2006 - 03:19 PM

i tested with exec and system with php path and same problem.

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 July 2006 - 03:38 PM

This could be a permission issue. See what this gives you:

<?php
	$path = '/full/path/to/php/executable';
	echo '<pre>';
	echo 'Group: ', print_r(posix_getgrgid(filegroup($path)), true);
	echo '<br />';
	echo 'Owner: ', print_r(posix_getpwuid(fileowner($path)), true);
	echo '<br />';
	echo 'Permissions: ', substr(sprintf('%o', fileperms($path)), -4);
	echo '</pre>';
?>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 ciocan

ciocan
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 July 2006 - 03:50 PM

i found it :) ... in the second server the php path is /usr/local/bin/php and in the first is /usr/bin/php (I checked only with that path).
in the second server (bsd one) i can't run it with simply php (without path) like in the other server.

Is there a way (shell command or php settings from php.ini) to run php without path?
(like exec('php script.php');)

Radu
PS: thanks effigy for your help

#8 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 July 2006 - 03:56 PM

The bin directory would need to be in the path, which I believe Apache inherits from the shell it is started in.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users