[wp-trac] [WordPress Trac] #33055: Support Parallel HTTP Requests in WP_Http, et al

WordPress Trac noreply at wordpress.org
Mon May 23 18:15:35 UTC 2016


#33055: Support Parallel HTTP Requests in WP_Http, et al
----------------------------+--------------------------
 Reporter:  wonderboymusic  |       Owner:  rmccue
     Type:  task (blessed)  |      Status:  assigned
 Priority:  high            |   Milestone:  4.6
Component:  HTTP API        |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  performance
----------------------------+--------------------------

Comment (by aaroncampbell):

 Replying to [comment:21 rmccue]:
 > Updated patch:
 > * Introduces `WP_HTTP_Requests_Response`, which acts as a backwards-
 compatible return value with `ArrayAccess` while allowing access to the
 underlying object.

 Actually, it doesn't seem that this is completely back-compat. I ran into
 this because we had code like the following:
 {{{#!php
 $response = wp_remote_get( $url );

 if ( is_wp_error( $response ) ) {
         return $response;
 }

 if ( ! is_array( $response ) || ! isset( $response['body'] ) ) {
         return new WP_Error( 'custom_error' );
 }

 }}}

 The issue is that PHP's is_array() returns false for objects that
 implement ArrayAccess. Obviously the old return was a real array, so it
 worked. Changing to check `instanceof ArrayAccess` as well as `is_array()`
 seems to work with old and new:

 {{{#!php
 if ( ! ( $response instanceof ArrayAccess || is_array( $response ) ) || !
 isset( $response['body'] ) ) {
         return new WP_Error( 'custom_error' );
 }
 }}}

 We might want to try to make devs aware as soon as possible, and maybe
 even check the plugin dir.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33055#comment:42>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list