Trigger deferred.php Via Shell Crontab

Trigger deferred.php Via Shell Crontab

digitalpoint

Well-known member
digitalpoint submitted a new resource:

Trigger deferred.php Via Shell Crontab - Allow an automated shell process to run deferred.php script

I had an issue where the deferred.php script was being called 400-500 times per minute by the normal method where end user activity triggers it. This will move the deferred.php triggering to a crontab job run in the shell by your server in an automated (and more controllable) fashion.

First, remove the deferred trigger from the PAGE_CONTAINER template. Simply remove this from that template:
Code:
{xen:if $hasAutoDeferred, RunDeferred}

Second, create a file in your /etc/cron.d/...

Read more about this resource...
 
I'm confident that this is unrelated and @digitalpoint has nothing to worry about. The only error I have gotten in 24 hours with this being the only change was

http://xenforo.com/community/threads/sitemap-for-xenforo-1-2-compatible.26785/page-36#post-663390

But I did figure out a solution

http://xenforo.com/community/threads/sitemap-for-xenforo-1-2-compatible.26785/page-36#post-663392

And it maybe only my setup. So no worries, but I'll make a note if it here just in case anyone else runs into it (or feels the need to take pre-emptive measures)
 
If you have something custom that is triggered by a cron task that is reliant on the permissions of the user the task is running on the server as, it could be an issue. You can change what system user it runs as in the cron file if you needed... Although not sure what couldn't be run as root.
 
I'm confident that this is unrelated and @digitalpoint has nothing to worry about. The only error I have gotten in 24 hours with this being the only change was

http://xenforo.com/community/threads/sitemap-for-xenforo-1-2-compatible.26785/page-36#post-663390

But I did figure out a solution

http://xenforo.com/community/threads/sitemap-for-xenforo-1-2-compatible.26785/page-36#post-663392

And it maybe only my setup. So no worries, but I'll make a note if it here just in case anyone else runs into it (or feels the need to take pre-emptive measures)
Had the same on my site last night. Even though I'm running as the root account.
 
Will this script processes anything in the xf_deferred table, updating cache's its horrible that these need to be run on the web and can't be run in the CLI in a screen or something else.
 
Just a small thought: I would run the cron as the web server user. You never know what deferred is going to do, and running it as the same user like when triggered from XenForo itself is always a good idea…
 
There are a couple of things to be aware of ... first, if you want to completely disable the RunDeferred javascript trigger - there are two more of them contained in the Admin side - you'll need to modify the Admin PAGE_CONTAINER and PAGE_CONTAINER_SIMPLE templates to remove RunDeferred from there as well.

Also, if you have XFMG installed, it has its own public facing page container - xengallery_page_container which also contains RunDeferred.

Finally, if you call the deferred.php script directly, there are quite a few things that could potentially break - especially anything wanting to generate full urls using XenForo_Link::buildPublicLink ... since this will try and extract server name information which simply isn't available when running PHP from CLI - that information comes directly from the web server, which is bypassed when using CLI.

(I discovered this when one of my addons tried to send emails with links to threads on the forum but sent them without the domain name - URLs were like this: http:///threads/mythread.1/ )

The simplest way to overcome this is to instead use cURL to trigger your deferred.php script, rather than triggering it directly from CLI.

Code:
* * * * *       curl --silent 'http://example.com/deferred.php' > /dev/null 2>&1

Because cURL will actually call your web server and ask it to communicate with PHP (just like any web browser will), scripts called this way have full access to all server variables, including the domain name, so everything will work exactly as expected.
 
I removed the {xen:if $hasAutoDeferred, RunDeferred} line but webpage still calling the deferred.php when i look the chrome developer console.

Can you help me @Sim or @digitalpoint ?
 
Last edited:
I removed the {xen:if $hasAutoDeferred, RunDeferred} line but webpage still calling the deferred.php when i look the chrome developer console.

Which templates did you remove that from? Which pages are you viewing that you still see it on?
 
Top Bottom