Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Using system() in PHP to call a program, I get a return value of 11

Hi all,

I am using system() in PHP to call a program that is installed called dot(GraphViz).  I get a return value of 11.  When I use system to call a shell command (i.e. ls -al), it works fine.  The dot command takes information that we feed to it and makes a graph from the information.

My environment:
RedHat 9
PHP 5.2.9
Apache 2.0.49

[root@thierry fonts]# ls -al /usr/local/bin/dot
-rwxr-xr-x    1 root     root        45457 Jun  4  2008 /usr/local/bin/dot

I'm not sure why this doesn't work.  Any help would be greatly appreciated.  Thanks.
<?
$command = "/usr/local/bin/dot -Tsvg -o/data/svg4customer.W61241121005W49fa00edba6b2.svg/data/svg4customer.W61241121005W49fa00edba6b2.graph.dot";
$data = system($command, $retval);
print "<pre>Running command:  $command\nReturn call: $retval</pre>";
$data = file_get_contents('/data/svg4customer.W61241121005W49fa00edba6b2.svg');
print "<pre>Contents of data file\n\n\n$data</pre>";
exit;
 
?>

Open in new window

0
KerryChin
Asked:
KerryChin
  • 10
  • 10
1 Solution
 
Michael701Commented:
um, are you missing a space before the /data

...6b2.svg/data/svg4custo...

...6b2.svg /data/svg4custo...
$command = "/usr/local/bin/dot -Tsvg -o/data/svg4customer.W61241121005W49fa00edba6b2.svg/data/svg4customer.W61241121005W49fa00edba6b2.graph.dot";
 
$command = "/usr/local/bin/dot -Tsvg -o/data/svg4customer.W61241121005W49fa00edba6b2.svg /data/svg4customer.W61241121005W49fa00edba6b2.graph.dot";

Open in new window

0
 
KerryChinAuthor Commented:
Hmmmm?  I copied it and pasted it.  I wonder why the paste missed that, but yes there was supposed to be a space there and there is in my original code, just not in the code above.

Oh one other thing I forgot to add, the directory I am writing to, /data can be written to by the php.  I can make the system call to touch a file and it will create the file in that directory, so I'm pretty sure it's not a permissions problem.
0
 
Michael701Commented:
You haven't mentioned, but I'll assume that the graph is not being generated.

How long does it take for the generation of the graph? Could 30 second timeout be an issue?

Is a return code of 11 explained in the graph documentation? Note: it could be that it's always returning a code of 11, unless you specifically check for the return code in terminal mode you wouldn't know.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
KerryChinAuthor Commented:
Yes, there is no output.  The graph is not generated.  I don't think a 30 second timeout is an issue.  Going from the .dot data file to an svg file is very quick.  We have another machine that is running a slightly older version of PHP and it generates the file in less than a second.

I have not been able to find any documentation from GraphViz explaining what a code 11 is.  I thought it was a php return code since the command runs fine if I run it from a shell.
0
 
Michael701Commented:
"slightly older version of PHP" what versions? Could this be a php version issue? or do you think it's a linux rights issue?
0
 
KerryChinAuthor Commented:
The machine it works on is RedHat ES 4 running PHP 5.2.5 and apache 2.2.0.  I tried to look at the release notes to see if there were any changes to security when making this system call but I didn't see any changes.  I thought this was a PHP issue since the "dot" command has the same permissions as other shell commands that run fine.
0
 
Michael701Commented:
Here's a long shot, try having it write the output to your website root, or the /tmp folder. Just to see if it works.
0
 
KerryChinAuthor Commented:
Same results.  No output file and return code 11.
0
 
Michael701Commented:
Let's compair the two systems: Here's a note from their website reported bugs.
-----------------

Problem:
configure fails to correctly find the location of the PHP includes if they are not in /usr.

In my case, they are in /usr/pubsw, but on other systems they may be in something like /usr/local

It should be possible to override this with a flag to configure or an ac_* variable.
0
 
KerryChinAuthor Commented:
I'm still new at PHP so please forgive my ignorance.  What are the PHP includes?  I do have a directory /usr/include but I also have a directory /usr/local/include

I dont' know if this helps but this was my configure command:
./configure --enable-bcmath --enable-dba --enable-dbase --enable-soap --enable-mbstring --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gettext --with-gmp --with-openssl --with-pspell --enable-shmop --enable-sockets --enable-wddx --with-zlib

The reason why I put this in is because I didn't set a new path when it comes to the includes (if that is possible).
0
 
Michael701Commented:
Looks like the bug report is about a file from this package that should be in the /usr folder. Take a look at the old machine /usr folder and see if there's any files that look like they might be part of this package.
0
 
KerryChinAuthor Commented:
The computer that it works on also has an /usr/include and a /usr/local/include.  The files in those directories have an extension of ".h".  /usr/include has a lot more files than /usr/local/include.  Oh wait!  There is a /usr/include/php directory and a /usr/local/include/php directory.  I've been looking for a list of files installed with PHP but I can't find that list.

I've changed my opinion on the problem.  Here's why.  The code I supplied above was in file (phptest.php)  that I access through a webpage.  When I access this through the webpage, I get teh return code of 11.  I decided to try running the file through the command prompt:

php phptest.php

And the command worked.  Now I know it has to be permissions since the PHP can run the file but when run by the webserver, it does not work.  Not to figure out which permissions to change.  The files seem to have all the same permissions as the one on the working server.  Any thoughts or ideas?
0
 
Michael701Commented:
does /data have 777 rights?
is apache the owner and group?
0
 
KerryChinAuthor Commented:
/data is does have 777 rights.  Apache is run by user nobody but nobody is not in the owner or the group.
0
 
Michael701Commented:
if you try the command without the -o option does it spew a bunch of data to the browser page?

This would tell if the program fails to execute, or if it's failing to write the data to an output file.
0
 
KerryChinAuthor Commented:
Without the -o option, I get the same result.  There is not a "spew of data" and return code 11.
0
 
Michael701Commented:
At this point I'd email the graphviz people and ask what causes return code 11.
0
 
KerryChinAuthor Commented:
I contacted GraphViz and they said that return code 11 is "EAGAIN".  I'm not sure what that means but from a quick search, I believe that message has to do with sockets.  I'm not sure how sockets come into play with my program though.  Now I'm mostly confused.  I still think it's some sort of permissions problem since apache is running as nobody, but I can't resolve which permission is the issue.  The .dot file has permissions of 644, the directory has permissions of 777 and executable dot has permissions of 755.  So all seems right.  I wonder if this is a PHP bug?
0
 
Michael701Commented:
It also has to do with create a fork, when you call the system command it creates another job to run the task. This is failing, there are of course a bunch of different things that could cause it to fail. one being memory. how complex is this chart? can you test with a super simple chart? (I'd guess it would still fail)

There should be system logs that show the error, not sure if they'd give any more info as to why.

I wonder if php could call they program using the sudo command as a different user.
0
 
KerryChinAuthor Commented:
ok I was getting frustrated and wanted to see what would happen if I was the nobody user and ran the command.  So I allowed nobody to have a shell and I ran the command.  It ran fine.  Then I ran the php script at the command line and it ran fine.  I am really confused now.  So it really isn't a permission's problem it is a forking problem (no pun intended).  With a simpler chart, it still had problems when accessing the script through the site but worked fine at the command line.

As for memory, this server has 1GB of Ram and in the php.ini the memory_limit =16M.  I see nothing in the system logs about the error.  Which log in particular are you talking about? /var/log/messages?

Thanks for all your help.  If you have any more suggestions, please let me know.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 10
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now