2

I'm importing Real Estate properties every 30 minutes into my website. I have a controller action that triggers this but the import is extremely slow and blocks the entire site.

Right now I'm triggering the imports with this code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_exec($ch);
curl_close($ch);

Where the url is the cron url of the feed.

3
  • What's the reason you don't point the cron job directly at the FeedMe url?
    – dmatthams
    Commented Nov 6, 2019 at 11:35
  • Because I first need to generate the json file before I can import it. It's a dynamic thing.
    – Kobe Aerts
    Commented Nov 6, 2019 at 22:08
  • Hey, I've had to do this today so have updated my answer with the solution I have: craftcms.stackexchange.com/a/32955/526
    – dmatthams
    Commented Nov 11, 2019 at 15:10

2 Answers 2

1

FeedMe shows you what the import trigger endpoint that you can use with curl in the feed configuration.

1
  • That's what I'm doing right now but my controller action seems to handle the import synchronous and waits for it to end.
    – Kobe Aerts
    Commented Nov 6, 2019 at 22:10
1

One potential way is to trigger curl from your plugin with exec:

// Set the feed me URL
$url =  'http://your.domain/actions/feed-me/feeds/run-task?direct=1&feedId=1&passkey=FwafY5kg3c'

// Build the curl command with the url
$cmd = 'curl --silent --compressed "'.$url.'"';

// Execute the command in the background
exec($cmd . " > /dev/null &");

That should then run the task using another process.

You will likely need to enable exec() function on your environment.

Even better if you use a daemon to process your queue with a nice command (if not have a look here) it will run as a low priority task and slow your front-end down less.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.