You are not logged in.

#1 2016-01-04 20:03:42

jsalk
Member
Registered: 2015-06-20
Posts: 26

php exec function not writing files correctly - SOLVED

I have developed web pages to present system information to a user.  I have used these web pages under debian and 32-bit Arch linux.  I am switching over to x86_64 version of Arch and all exec functions work except one.

exec (reboot);
exec (shutdown -h now):
exec (nmap -sP 192.168.1.* > /var/www/data/netdevices.txt);

All of these commands and more work just fine.  So I know I have all the permissions set correctly for user http.  But for some reason, I have one command that does not work:

exec(aplay -l > /var/www/data/play.txt);

It writes a file, but the file is empty.

I can run this command in a terminal and it works fine.  I can run a batch file with the same command (from a terminal) and it works fine.  But if I try and run the command in a php file, either directly or by running a batch file with that command, it writes a file, but the file is empty. (I am monitoring the file with Crimson Editor which informs me when a file is changed.  In this case, it let's me know the file is changed but the contents are empty.  When I run the command in a terminal directly or through the use of a batch file, the file is written with the correct contents.

What baffles me is that this problem does not exist on my 32-bit version of Arch.

Any ideas would be appreciated.

- Jim

Last edited by jsalk (2016-01-05 20:33:51)

Offline

#2 2016-01-04 20:28:49

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

Re: php exec function not writing files correctly - SOLVED

Try &> instead of > to see what's output to stderr.

FWIW, I think whichever user that is used to execute the script needs to be either root or in audio group. You don't need to do that for current user is because by default systemd has an udev rule that set ACLs on /dev/snd/*

Last edited by tom.ty89 (2016-01-04 20:31:59)

Offline

#3 2016-01-05 20:33:38

jsalk
Member
Registered: 2015-06-20
Posts: 26

Re: php exec function not writing files correctly - SOLVED

I added http to the audio group yesterday.  At first it made no difference.  Today it all works fine.  So that must have been it.  Thanks.

- Jim

Offline

Board footer

Powered by FluxBB