Shell script works fine from shell but doesn’t work as expected when executed via PHP “shell_exec” code

This record.sh script shell is here and works fine on command line to record an MP4 file from a local flv live stream:

DATE=`date +"%d-%m-%Y-%T"`
if [ -s NAMESTREAM ]
then
cat config.php | dos2unix | grep auth | grep username | \
awk -F ' ' '{print $3}' | sed "s/'//g" | sed "s/;//g" | while read VAR
do echo $VAR > RECSTREAM
echo "Starting recording ..."
ffmpeg -i "rtmp://localhost/hls/$VAR" -crf 19 videos/"$VAR"_"$DATE".mp4
done
else
echo "Streaming is not started, please start it before"
fi

I send a shell_exec to call the last shell script in a php script like this:

$old_path = getcwd();
chdir('/usr/local/nginx/html/mydir');
$output = shell_exec('nohup ./record.sh >/dev/null 2>/dev/null &');
chdir($old_path);

The MP4 video files are generated but unreadable with VLC, etc… It seems that the problem is due to my PHP script but I am not able to know why.

When executing from the shell command line: PHP myphpscript.php works fine, MP4 video files are OK. But from the PHP web page, the MP4 video files are corrupted.

Any ideas? Any param to test in FFmpeg to have a good mp4 video file?