且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何强制命令行的PHP版本?

更新时间:2023-02-22 09:39:18

如果两者都安装,你所需要做的就是使用相关的PHP二进制文件运行脚本。 p>

例如:

  //使用PHP二进制文件/ usr / bin / php 
* * * * * root / usr / bin / php -n/path/to/script.php

  //使用位于/ var / php5 
* * * * * root / var / php5 -n/path/to/script.php


b $ b

您需要知道的是PHP CLI二进制文件的完整文件系统路径,并调用相关代码来运行您的代码。


I am hosted with 1and1.com, and I have setup my files to be parsed with php5 using .htaccess.

But that only works in apache, and not in command line, which defaults to the server default php4.

So currently I can not setup cron jobs to run my code as php5. Any ideas?

If both are installed, all you need to do is run the script using the relevant PHP binary.

So for example:

 // Runs using the PHP binary located at /usr/bin/php
 * * * * * root /usr/bin/php -n "/path/to/script.php"

or

 // Runs using the PHP binary located at /var/php5
 * * * * * root /var/php5 -n "/path/to/script.php"

All you need to know is the full file system path of the PHP CLI binaries, and call the relevant one to run your code.