Bash script to run php script

前端 未结 9 632
悲&欢浪女
悲&欢浪女 2020-12-07 20:30

I have a php script that I want to be run using a bash script, so I can use Cron to run the php script every minute or so.

As far as I\'m aware I need to create the

相关标签:
9条回答
  • 2020-12-07 21:07

    If you don't do anything in your bash script than run the php one, you could simply run the php script from cron with a command like /usr/bin/php /path/to/your/file.php.

    0 讨论(0)
  • 2020-12-07 21:13

    A previous poster said..

    If you have PHP installed as a command line tool… your shebang (#!) line needs to look like this: #!/usr/bin/php

    While this could be true… just because you can type in php does NOT necessarily mean that's where php is going to be... /usr/bin/php is A common location… but as with any shebang… it needs to be tailored to YOUR env.

    a quick way to find out WHERE YOUR particular executable is located on your $PATH, try.. ➜which -a php ENTER, which for me looks like..

    php is /usr/local/php5/bin/php
    php is /usr/bin/php
    php is /usr/local/bin/php
    php is /Library/WebServer/CGI-Executables/php

    The first one is the default i'd get if I just typed in php at a command prompt… but I can use any of them in a shebang, or directly… You can also combine the executable name with env, as is often seen, but I don't really know much about / trust that. XOXO.

    0 讨论(0)
  • 2020-12-07 21:23
    #!/usr/bin/env bash
    PHP=`which php`
    $PHP /path/to/php/file.php
    
    0 讨论(0)
提交回复
热议问题