Jump to content

[SOLVED] PHP CLI works but web does not for some things


kkling

Recommended Posts

I am trying to get SNMP information polled from a device and it works if I execute the script from the server using php somefile.php however if i put it on a webpage it only displays "done" which i put in to verify it is doing something.

 

<?php
$command = "snmpwalk -c public -v 1 10.8.38.74 transmission.127.1.1.4.1.5.3";
$mstrng = shell_exec($command);
echo "<pre>$mstrng</pre>";
echo "done";
?>

Off the CLI it will return: 

<pre>SNMPv2-SMI::transmission.127.1.1.4.1.5.3 = INTEGER: 414

</pre>done

 

Any help would be great, I have logging enabled, but nothing is returned in there either.  Thanks!

Humm well, shell_exec is disabled when PHP is running in safe mode. so that could be the cause.. infact most Program execution Functions are disabled on shared servers.. check with your host provider or check their not disabled!

I am able to do simple things like 'ls -al'  or even 'php -i' from shell_exec (which returns the same php -i as the CLI does which works fine), I have full rights to the server (It's an internal server that doesn't touch the internet) also if there is anything i could pull out that would help I can. shell_exec is not disabled in the php.ini, and safe_mode is off from php -i.

Yes, if i run the php script from the CLI it'll even work and display the integer value (Posted above)

<pre>SNMPv2-SMI::transmission.127.1.1.4.1.5.3 = INTEGER: 414

</pre>done

 

so from just running php somefile.php  off the CLI i will get the correct info. Then if i pull that page up, all i see is the comment i made "done" and no other text If i view source i see

<pre></pre>done

but there is no output of the INTEGER etc.  if i replace the snmpwalk with ls-al i will get a directory output though.

Humm

only think i can think of is compare the info from

php -i

to

<?php phpinfo(); ?>

.. either that or maybe permissions or apache!

 

if that doesn't reveal anything then maybe try posting in the PHP Installation & Configuration section, (keep this one open, Just incase) but if you do post their include a link back to here saying you start it here as dup posts are not allowed but in this case i think it will be okay.

Here is something interesting that I did not see in the logs before:  "sh: snmpwalk: command not found"  but if i run the php file directly off the server no error is displayed and it works.

 

which snmpwalk

/usr/local/bin/snmpwalk

 

After testing. I realized the script requires the entire path  "/usr/local/bin/snmpwalk" instead of just snmpwalk.  I've been fighting with this for a long time. Thanks for helping.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.