I need to update the details of a few thousand accounts and I can't do it with pure MySQL, I need php too. With all the loops that's probably around 100k mysql queries. I chose to do it via a button that makes an ajax request and when testing i locally the request is still pending after hours. I know that a single loop works as intended. If I do the same thing on the server will it keep executing the queries after I go offline? Will too many queries have effect on the website's users? Tried shortening the process by having the loop just add to a query string every time it needs to update the database and execute it all at once when it's all over, but

$wpdb->query( 
    $wpdb->prepare( 
        $query_string,
        $value_parameters_array 
    )
);

doesn't seem to do anything when testing with a single loop.

  • It really isn't clear what you are doing. – s_ha_dum Oct 30 '15 at 13:38
  • @s_ha_dum I am sending an ajax request that starts running a php code that creates several thousand MySQL queries like $wpdb->query($wpdb->prepare('stuff', $var1, $var2, $var3));. The whole thing can take up to 40 hours, so I am wondering if there is any faster way, or in case there isn't, will it continue to run until it's done after the computer that made the request is turned off. – Nadroev Oct 30 '15 at 15:42
  • Still too vague... – s_ha_dum Oct 30 '15 at 15:44
  • @s_ha_dum Sorry, but I can't paste my entire code, what information do you want? – Nadroev Oct 30 '15 at 16:00

There is typically a hosting limit to how long PHP can run, on shared this can be as low as 60-90 seconds. Since WP's Ajax is just another instance of PHP load it will likely be subject to that restriction.

Even if it's disabled any error risks knocking such a long running process out.

Unfortunately there isn't really any mechanism in WP for running long tasks. You might want to look for other PHP solutions for it.

The closest WP option would be to use WP cron to toggle task periodically, which will grab smaller share, process it, and track progress.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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