kkling Posted April 7, 2009 Share Posted April 7, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/ Share on other sites More sharing options...
MadTechie Posted April 7, 2009 Share Posted April 7, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-803946 Share on other sites More sharing options...
kkling Posted April 7, 2009 Author Share Posted April 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-803974 Share on other sites More sharing options...
MadTechie Posted April 7, 2009 Share Posted April 7, 2009 Sorry but i have to ask, is snmpwalk installed and working.. ie have you tried it from terminal ? Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-803976 Share on other sites More sharing options...
kkling Posted April 7, 2009 Author Share Posted April 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-803984 Share on other sites More sharing options...
MadTechie Posted April 7, 2009 Share Posted April 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-803996 Share on other sites More sharing options...
kkling Posted April 7, 2009 Author Share Posted April 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-803997 Share on other sites More sharing options...
MadTechie Posted April 7, 2009 Share Posted April 7, 2009 : cool.. A problem always seams easier after you spend some explaining the problem to others.. Quote Link to comment https://forums.phpfreaks.com/topic/153054-solved-php-cli-works-but-web-does-not-for-some-things/#findComment-804005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.