PHP Scripting - Execute CLI Job With Key

Foxtrek_64

Active member
Hi all,

Hopefully someone here can help me out with some PHP scripting. What need is fairly basic, but PHP is still fairly alien to me.

Essentially, I want to be able to have an external service, in my case EasyCron, make a call to a php file and have it execute the xf:run-jobs activity, but I'd like it to be protected by a key so not just anyone can do this.

Psuedo-code below:
C#:
private static readonly string keyValue = "1234";

public HttpResponse Execute(string key)
{
    return keyValue == key
        ? XF.RunJobs()
        : HttpResponse.AccessDenied;
}

In practice the key would likely be a guid or some other randomly-generated value, but 1234 works to illustrate the example.
 
Exactly what are you trying to protect xf:run-jobs from?

If someone can execute arbitrary CLI commands on your server, you have much bigger issues to deal with - as in, they can do anything they want with your server.

I work on the assumption that CLI is secure.
 
Exactly what are you trying to protect xf:run-jobs from?

If someone can execute arbitrary CLI commands on your server, you have much bigger issues to deal with - as in, they can do anything they want with your server.

I work on the assumption that CLI is secure.
It's moreso that I want to have a class that I can call from an external service that
  1. Can only execute xf:run-jobs
  2. Has some sort of verification check using a secure key
I'm using shared hosting to run my site, and while my host does offer a cron service, the maximum frequency is once per hour. Xenforo's docs specify this should be run minutely, so I want to enable EasyCron to handle this.

This is also how I have it set up with Invision Community, which I'm in the progress of migrating from.
 
If you can't run a proper cron job, just use the activity based trigger - that's what it's there for?
 
It's moreso that I want to have a class that I can call from an external service that
  1. Can only execute xf:run-jobs
  2. Has some sort of verification check using a secure key
I'm using shared hosting to run my site, and while my host does offer a cron service, the maximum frequency is once per hour. Xenforo's docs specify this should be run minutely, so I want to enable EasyCron to handle this.

This is also how I have it set up with Invision Community, which I'm in the progress of migrating from.

Have it run https://yoursite.com/job.php no key is needed
 
Back
Top Bottom