duanjian7617 2019-05-24 12:35
浏览 197

如果从Laravel创建,从php创建的命令不起作用

I'm trying to trigger a Laravel command at a specific time, that command is created from a web interface (people can schedule an event to happen). It's not like crontab and the Laravel's Schedule commands because mine is not recurrent and just a one shot at a custom time. On my local environment (Homestead) it works. On the pre-production server (CentOS) it doesn't but only with Laravel.

If I run a command like <?php echo exec("echo '/usr/local/php/bin/php artisan platform:publish-scheduled 25 > plap.txt' | at now + 1minute"); from bash I get the result of AT printed which tells me the PID and execution time. Then at the next minute the file is created with the result of the Laravel command, works fine. But if I run echo exec("echo '/usr/local/php/bin/php artisan platform:publish-scheduled 26 > plap.txt' | at now + 1minute"); from a Laravel controller (responding to my web interface): the command is successfully scheduled and disappears from atq on due time but nothing more happens, the Laravel command is not executed, the plap.txt is not created.

The first method (executing PHP script from bash) gives me this: at -c 99

#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
XDG_SESSION_ID=2804837; export XDG_SESSION_ID
HOSTNAME=iZwz9c70yc8miek8g0g2ilZ; export HOSTNAME
SHELL=/bin/bash; export SHELL
HISTSIZE=10000; export HISTSIZE
SSH_CLIENT=124.78.94.138\ 51362\ 22; export SSH_CLIENT
SSH_TTY=/dev/pts/0; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=38\;5\;27:ln=38\;5\;51:mh=44\;38\;5\;15:pi=40\;38\;5\;11:so=38\;5\;13:do=38\;5\;5:bd=48\;5\;232\;38\;5\;11:cd=48\;5\;232\;38\;5\;3:or=48\;5\;232\;38\;5\;9:mi=05\;48\;5\;232\;38\;5\;15:su=48\;5\;196\;38\;5\;15:sg=48\;5\;11\;38\;5\;16:ca=48\;5\;196\;38\;5\;226:tw=48\;5\;10\;38\;5\;16:ow=48\;5\;10\;38\;5\;21:st=48\;5\;21\;38\;5\;15:ex=38\;5\;34:\*.tar=38\;5\;9:\*.tgz=38\;5\;9:\*.arc=38\;5\;9:\*.arj=38\;5\;9:\*.taz=38\;5\;9:\*.lha=38\;5\;9:\*.lz4=38\;5\;9:\*.lzh=38\;5\;9:\*.lzma=38\;5\;9:\*.tlz=38\;5\;9:\*.txz=38\;5\;9:\*.tzo=38\;5\;9:\*.t7z=38\;5\;9:\*.zip=38\;5\;9:\*.z=38\;5\;9:\*.Z=38\;5\;9:\*.dz=38\;5\;9:\*.gz=38\;5\;9:\*.lrz=38\;5\;9:\*.lz=38\;5\;9:\*.lzo=38\;5\;9:\*.xz=38\;5\;9:\*.bz2=38\;5\;9:\*.bz=38\;5\;9:\*.tbz=38\;5\;9:\*.tbz2=38\;5\;9:\*.tz=38\;5\;9:\*.deb=38\;5\;9:\*.rpm=38\;5\;9:\*.jar=38\;5\;9:\*.war=38\;5\;9:\*.ear=38\;5\;9:\*.sar=38\;5\;9:\*.rar=38\;5\;9:\*.alz=38\;5\;9:\*.ace=38\;5\;9:\*.zoo=38\;5\;9:\*.cpio=38\;5\;9:\*.7z=38\;5\;9:\*.rz=38\;5\;9:\*.cab=38\;5\;9:\*.jpg=38\;5\;13:\*.jpeg=38\;5\;13:\*.gif=38\;5\;13:\*.bmp=38\;5\;13:\*.pbm=38\;5\;13:\*.pgm=38\;5\;13:\*.ppm=38\;5\;13:\*.tga=38\;5\;13:\*.xbm=38\;5\;13:\*.xpm=38\;5\;13:\*.tif=38\;5\;13:\*.tiff=38\;5\;13:\*.png=38\;5\;13:\*.svg=38\;5\;13:\*.svgz=38\;5\;13:\*.mng=38\;5\;13:\*.pcx=38\;5\;13:\*.mov=38\;5\;13:\*.mpg=38\;5\;13:\*.mpeg=38\;5\;13:\*.m2v=38\;5\;13:\*.mkv=38\;5\;13:\*.webm=38\;5\;13:\*.ogm=38\;5\;13:\*.mp4=38\;5\;13:\*.m4v=38\;5\;13:\*.mp4v=38\;5\;13:\*.vob=38\;5\;13:\*.qt=38\;5\;13:\*.nuv=38\;5\;13:\*.wmv=38\;5\;13:\*.asf=38\;5\;13:\*.rm=38\;5\;13:\*.rmvb=38\;5\;13:\*.flc=38\;5\;13:\*.avi=38\;5\;13:\*.fli=38\;5\;13:\*.flv=38\;5\;13:\*.gl=38\;5\;13:\*.dl=38\;5\;13:\*.xcf=38\;5\;13:\*.xwd=38\;5\;13:\*.yuv=38\;5\;13:\*.cgm=38\;5\;13:\*.emf=38\;5\;13:\*.axv=38\;5\;13:\*.anx=38\;5\;13:\*.ogv=38\;5\;13:\*.ogx=38\;5\;13:\*.aac=38\;5\;45:\*.au=38\;5\;45:\*.flac=38\;5\;45:\*.mid=38\;5\;45:\*.midi=38\;5\;45:\*.mka=38\;5\;45:\*.mp3=38\;5\;45:\*.mpc=38\;5\;45:\*.ogg=38\;5\;45:\*.ra=38\;5\;45:\*.wav=38\;5\;45:\*.axa=38\;5\;45:\*.oga=38\;5\;45:\*.spx=38\;5\;45:\*.xspf=38\;5\;45:; export LS_COLORS
PATH=/root/.yarn/bin:/usr/local/nginx/sbin:/usr/local/php/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin; export PATH
MAIL=/var/spool/mail/root; export MAIL
PWD=/data/wwwroot/mydomain.cn; export PWD
LANG=en_US.UTF-8; export LANG
HISTCONTROL=ignoredups; export HISTCONTROL
HOME=/root; export HOME
SHLVL=2; export SHLVL
LOGNAME=root; export LOGNAME
LC_CTYPE=UTF-8; export LC_CTYPE
SSH_CONNECTION=124.78.94.138\ 51362\ 120.76.29.164\ 22; export SSH_CONNECTION
LESSOPEN=\|\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
XDG_RUNTIME_DIR=/run/user/0; export XDG_RUNTIME_DIR
cd /data/wwwroot/platform\-dev\.phoceis\.cn || {
     echo 'Execution directory inaccessible' >&2
     exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER6748b86c'
php artisan platform:publish-scheduled 25 > plap.txt

marcinDELIMITER6748b86c

The one from Laravel gives me this: at -c 100

#!/bin/sh
# atrun uid=1001 gid=1001
# mail root 0
umask 22
USER=www; export USER
TEMP=/tmp; export TEMP
PATH=/usr/local/bin:/usr/bin:/bin; export PATH
PWD=/data/wwwroot/mydomain.cn/public; export PWD
SHLVL=1; export SHLVL
HOME=/home/www; export HOME
TMP=/tmp; export TMP
cd /data/wwwroot/platform\-dev\.phoceis\.cn/public || {
     echo 'Execution directory inaccessible' >&2
     exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER5976c072'
/usr/local/php/bin/php artisan platform:publish-scheduled 26 > plap.txt

marcinDELIMITER5976c072

not the same user, but www owns the folder.

The problem is that I don't even know where any error message would go in that situation, couldn't find any error log related to that.

I specify the full path to the PHP binary (which was the first flaw in my script) so there is no problem about PHP path.

I don't know what to try anymore. Please help!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块