Base PHP version + PHPswitcher & setting PHP environment in cron job script?

  • I use whmcs 7.9.2 with PHP 7.2 (phpswitcher) but the main system runs under PHP 7.0 ...

    WHMCS works so far with PHP 7.2 but shows a warning message about different PHP version for the whmcs cron jobs

    how can i set the PHP environment in whmcs cron script or as a command for the cronjob to use the compiled PHP 7.2 environment?

    Code
    1. PHP 7.2 path
    2. /opt/phpswitcher/20200223/php7.2/sbin/psw7.2-fpm
    3. cron job
    4. 30 7 * * * php -q /var/www/virtual/mydomain.tld/crons/cron.php &> /dev/null #billing
  • If I run the whmcs cron jobs as the web owner (user) all of the cron job sessions goes into the system main /tmp folder, so today I have found about thousands of cron session files inside.

    The website is using a phpswitcher w/ PHP 7.2 and works without any issues ... all website or whmcs sessions are stored in the phptmp session folder of the webfolder, it just happens with the cron jobs.

    Is there any way to set the session path for the cron jobs when extecuted via PHPswitcher /opt/php....../7.2/bin/php -q to the webfolder phptmp folder?

  • I think not .. you can try entering the domain's phptmp folder and do a manual execution of your task from that point

    if you don't need the execution outputs you can put at the end of your execution >/dev/null 2> & 1


    If you need to verify that information, you can set a cron task that deletes those files that are older

    For example this deletes every 21 days the files

    find / tmp -name "*" -atime +21 -type f -print -exec rm {} \; > /dev/null 2> & 1

    I really do my tasks, scheduled I don't need to see the output and those that really interest me and are done, I send the output by mail


    regards

  • Or you could just set the correct env variable in your cron job.

    Have a look at the first line:

  • the TMPDIR variable has no effect, but the cron jobs are executed correctly even if PHP CLI is running under PHP 7.0 and whmcs is working with PHP 7.2 ... I think it works with the different PHP CLI version and the warning message from whmcs can be ignored.

    thank you guys, take care of you!

  • yep maybe due to using of self compiled PHP version

    all of the whmcs PHP files are ioncubed ... but I could try to add the TMPDIR path above the ioncube part inside of the cron.php ... in my user crontab has no effect, after restart the cron service

  • And what happens you you run the following in your crontab ?

    Code
    1. */5 * * * * export TMPDIR=/var/www/virtual/your-whmcs-domain.xxx/phptmp && /opt/phpswitcher/your/php7.2/executable /var/www/virtual/your-whmcs-domain.xxx/00_private/crons/cron.php

    Or, just for test:

    Create a php file with the following contents:

    PHP
    1. <?php echo sys_get_temp_dir(); ?>

    and name it test.php

    What's the output of:

    Code
    1. /path/to/your/php7.2/executable test.php

    What's the output of:

    Code
    1. export TMPDIR=/var/www/virtual/your-whmcs-domain.xxx/phptmp && /path/to/your/php7.2/executable test.php
  • thanks kees. see results below