Solved

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

Posted on 2009-05-06
20
240 Views
Last Modified: 2012-05-06
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
Comment
Question by:KerryChin
  • 10
  • 10
20 Comments
 
LVL 19

Expert Comment

by:Michael701
ID: 24317462
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
 

Author Comment

by:KerryChin
ID: 24317677
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
 
LVL 19

Expert Comment

by:Michael701
ID: 24321825
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
 

Author Comment

by:KerryChin
ID: 24328452
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
 
LVL 19

Expert Comment

by:Michael701
ID: 24328627
"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
 

Author Comment

by:KerryChin
ID: 24329057
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
 
LVL 19

Expert Comment

by:Michael701
ID: 24329566
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
 

Author Comment

by:KerryChin
ID: 24329707
Same results.  No output file and return code 11.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24329890
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
 

Author Comment

by:KerryChin
ID: 24330431
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 19

Expert Comment

by:Michael701
ID: 24331461
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
 

Author Comment

by:KerryChin
ID: 24336857
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
 
LVL 19

Expert Comment

by:Michael701
ID: 24337007
does /data have 777 rights?
is apache the owner and group?
0
 

Author Comment

by:KerryChin
ID: 24337078
/data is does have 777 rights.  Apache is run by user nobody but nobody is not in the owner or the group.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24337315
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
 

Author Comment

by:KerryChin
ID: 24337449
Without the -o option, I get the same result.  There is not a "spew of data" and return code 11.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 24340507
At this point I'd email the graphviz people and ask what causes return code 11.
0
 

Author Comment

by:KerryChin
ID: 24364298
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
 
LVL 19

Accepted Solution

by:
Michael701 earned 500 total points
ID: 24365046
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
 

Author Comment

by:KerryChin
ID: 24367770
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now