wordpress - Asynchronous php code in WP Plugin -



wordpress - Asynchronous php code in WP Plugin -

need create block of code asynchronous rest of code. going collect wp posts , send post request url. plugin should run asynchronously , doesn't hamper functioning of wordpress site.

for ($x=0; $x<=n; $x++) { $data = posts[$x]; $ch = curl_init('http://myurl.com/'); curl_setopt($ch, curlopt_customrequest, "post"); curl_setopt($ch, curlopt_postfields, $data); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_httpheader, array( 'accept: application/json', 'content-length: ' . strlen($data)) ); $result = curl_exec($ch); curl_close($ch); }

the proper way process asynchronous requests in wordpress utilize wp-cron schedule event. can either schedule run once, or on interval. see guides on setting here. 2 main functions check out wp_schedule_event() , wp_schedule_single_event().

one thing maintain in mind because code running when there request, if there low traffic it's possible scheduled event won't run when expected. wrote article on site regarding how can utilize crontab in conjunction wp-cron more accurately schedule events: http://justinsilver.com/technology/wordpress/disable-wp-cron-wordpress/.

php wordpress curl asynchronous wordpress-plugin

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -