Skip to main content

How to setup Live Helper Chat cronjob?

Default cronjob setup

LHC uses cronjob for background chats assignment and maintenence tasks.

php cron.php -s site_admin -c cron/workflow

This cronjob does the following things.

  • Automatic chat's transfer workflow
  • Executes unanswered chats workflow
  • Executes automatic chat's purging/closing
  • Executes round robin workflow
  • Auto Responder for third party services. WhatsApp, Facebook, MessageBird
  • Please note that the auto-responder functionality is designed to work for a maximum of 500 active/pending/bot chats. If there are more than 500 in total of active/bot/pending chats, it will only operate for the first 500.

Should be run every minute or even more frequent if you want live chat auto assignment workflow to feel like live. See performance tweaks

Shell script example to run workflow every 5 seconds

Cronjob example

* * * * * cd /home/lhc/cronjobs && ./ >> /dev/null 2>&1

Shell script. Set your paths.


for i in {1..12}
if [ ! -f $fileCron ];
touch $fileCron;
cd /home/lhc/lhc-official/lhc_web && /usr/bin/php cron.php -s site_admin -c cron/workflow >> workflow.log
# You can comment out line below if you are not using transfer between departments workflow
cd /home/lhc/lhc-official/lhc_web && /usr/bin/php cron.php -s site_admin -c cron/transfer_workflow >> transfer_workflow.log
echo "$(tail -1000 workflow.log)" > workflow.log
rm -f $fileCron;
if [ `stat --format=%Y $fileCron` -le $(( `date +%s` - 30 )) ]; then
rm -f $fileCron;
echo "Already running"
sleep 5

Statistic reporting cronjob

This cronjob sends saved reports. Should be run every minute

* * * * * cd web_root_folder/lhc_web && /usr/bin/php cron.php -s site_admin -c cron/report > /dev/null 2>&1

Chat archive cronjob setup

php cron.php -s site_admin -c cron/archive

This cronjob does automatic chat's archiving

Department availability cronjob

This cronjob tracks department availability. It's collected data is used to generate department availability statistic data.

php cron.php -s site_admin -c cron/departament-availability

Should be run every minute.

Chats anonymization

If you have setup chat's anonymization you should run this cronjob.

php cron.php -s site_admin -c cron/encrypt

Should be run every 12 hours or so.

Transfers between departments workflow

If you are using transfer between department workflow. You can setup this cronjob. So chat would be transferred to other department even if the visitor left the chat. By default, transfer happens only if visitor in the chat.

In order for this script being executed in chat configuration this option has to be enabled

Should cronjob run departments transfer workflow, even if user leaves a chat

Cronjob script

php cron.php -s site_admin -c cron/transfer_workflow

Login monitoring

This cronjob monitors for users matching Disable user automatically if from last login passed X number of days and Force user logout if last login was X hours ago

Should be run every hour

php cron.php -s site_admin -c cron/login_monitoring


php cron.php -s site_admin -c cron/notifications
  1. Send notification to those chat's where visitor has unread message from operator.
  2. Last sync stopped 4 - 5 minutes. (It sends last unread message. Like we don't know what message was seen by visitor exactly and which not)
  3. We should log within chat. Last notified message id. Also mark chat as notification was send
  4. If operator sends another message. We reset flag about notification. So cronjobs sends notification only for new messages. Since we have logged it.
  5. Notification should be send for all chats. Not only active one where visitor did not read. But also for closed one.

Should be run every 5 minutes or so.


Either you are using chats or elasticSearch extension they can have a saved Views

This command should be run every minute or so. Views also supports php-resque. Make sure you are executing lhc_views_update job queue.

php cron.php -s site_admin -c cron/update_views

If a view takes more than 1 seconds to update. It will be logged in audit log with these parameters

  • source - View
  • category - slow_view

So you can find afterward them.

Files maintenance

It automatically deletes files based on files maintenance settings.

php cron.php -s site_admin -c cron/util/maintain_files

Should be run every few hours or so.

Database maintenance

It makes sense time from tim run this script to optimize users departments table. As this table get's a lot of updates.

php cron.php -s site_admin -c cron/util/maintain_database

Should be run every few hours or so.

Statistic cronjob

This cronjob calculates a statistic for two attributes of department

  • avg_chat_duration - average chat duration. Can be used in continous webhooks. This cronjob data is used only in continuous webhooks.
  • avg_wait_time - calculates average chat time. This value is used in setting pending text to average wait time.

For what period this data is calculated depends on your settings in Live help configuration (tab) -> Chat (section) -> Statistic -> Configuration (tab). Frequency of cronjob should depend on your use case. You can calculate both values if you run. I would recommend just calculate the part you want.

php cron.php -s site_admin -c cron/stats/department
# Equal to
php cron.php -s site_admin -c cron/stats/department -p avg_chat_duration,avg_wait_time

Average chat duration. This one you can run less often.

php cron.php -s site_admin -c cron/stats/department -p avg_chat_duration

Let's run it every 12 hours

15 */12 * * * www-data cd /code && php cron.php -s site_admin -c cron/stats/department -p avg_chat_duration >> /dev/null 2>&1

Average wait time. This cronjob you can run more frequently. Depends on your requirements.

php cron.php -s site_admin -c cron/stats/department -p avg_wait_time

Let's run it every 5 minutes

*/5 * * * * www-data cd /code && php cron.php -s site_admin -c cron/stats/department -p avg_wait_time >> /dev/null 2>&1

Continuous webhooks cronjob

This cronjob should be running every 20 seconds. For simplified version you can run it every minute. This is a required cronjob for a continuous webhooks

php cron.php -s site_admin -c cron/webhook

Crontab command example. You should change /scripts and /code directories according to your environment.

* * * * * www-data cd /scripts && ./ >> /dev/null 2>&1

Shell script example running every 20 seconds



for i in {1..3}
if [ ! -f $fileCronHook ];
touch $fileCronHook;
cd /code && php cron.php -s site_admin -c cron/webhook >> cache/webhook.log
echo "$(tail -1000 cache/webhook.log)" > cache/webhook.log
rm -f $fileCronHook;
if [ `stat --format=%Y $fileCronHook` -le $(( `date +%s` - 30 )) ]; then
rm -f $fileCronHook;
echo "Already running"
sleep 20

Static cache

If you are using load balancers. E.g AWS Load Balancer it can happen that one instance is clearing a cache but browser makes request to another instance so it happens that static file CSS/JS is not found.

This will generate new static cache without removing old files. Means you won't override any of existing files so not github conflicts.

php cron.php -s site_admin -c cron/util/generate_css

This will generate new static cache and remove all files from present static cache folders.

php cron.php -s site_admin -c cron/util/generate_css -p 1

To gain even more performance you can run gulp command to compress JS files.

gulp js-static

In all cases you will have to do before publishing to your fork.

git add .
git commit -a -m "Static cache"
git push origin master

How to add cronjob in extension?

Yes, extensions supports cronjobs. What you have to do is:

php cron.php -s site_admin -e customstatus -c cron/customcron

Example file in github which will executed.