src/Client.php
public function push(): array
    {
        $responseCollection = [];

        if (!$this->curlMultiHandle) {
            $this->curlMultiHandle = curl_multi_init();

            if (!defined('CURLPIPE_MULTIPLEX')) {
                define('CURLPIPE_MULTIPLEX', 2);
            }

            curl_multi_setopt($this->curlMultiHandle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
            curl_multi_setopt($this->curlMultiHandle, CURLMOPT_MAX_HOST_CONNECTIONS, $this->maxConcurrentConnections);
        }

        $mh = $this->curlMultiHandle;

        $i = 0;
        while (!empty($this->notifications) && $i++ < $this->nbConcurrentRequests) {
            $notification = array_pop($this->notifications);
            curl_multi_add_handle($mh, $this->prepareHandle($notification));
        }

        // Clear out curl handle buffer
        do {
            $execrun = curl_multi_exec($mh, $running);
        } while ($execrun === CURLM_CALL_MULTI_PERFORM);

        // Continue processing while we have active curl handles
        while ($running > 0 && $execrun === CURLM_OK) {
            // Block until data is available
            $select_fd = curl_multi_select($mh);
            // If select returns -1 while running, wait 250 microseconds before continuing
            // Using curl_multi_timeout would be better but it isn't available in PHP yet
            // https://php.net/manual/en/function.curl-multi-select.php#115381
            if ($running && $select_fd === -1) {
                usleep(250);
            }

            // Continue to wait for more data if needed
            do {
                $execrun = curl_multi_exec($mh, $running);
            } while ($execrun === CURLM_CALL_MULTI_PERFORM);

            // Start reading results
            while ($done = curl_multi_info_read($mh)) {
                $handle = $done['handle'];

                $result = curl_multi_getcontent($handle);

                // find out which token the response is about
                $token = curl_getinfo($handle, CURLINFO_PRIVATE);

                $responseParts = explode("\r\n\r\n", $result, 2);
                $headers = '';
                $body = '';
                if (isset($responseParts[0])) {
                    $headers = $responseParts[0];
                }
                if (isset($responseParts[1])) {
                    $body = $responseParts[1];
                }

                $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
                $responseCollection[] = new Response($statusCode, $headers, (string)$body, $token);
                curl_multi_remove_handle($mh, $handle);
                curl_close($handle);

                if (!empty($this->notifications)) {
                    $notification = array_pop($this->notifications);
                    curl_multi_add_handle($mh, $this->prepareHandle($notification));
                }
            }
        }

        if ($this->autoCloseConnections) {
            curl_multi_close($mh);
            $this->curlMultiHandle = null;
        }

        return $responseCollection;
    }
public function push(): array
    {
        $responseCollection = [];

        if (!$this->curlMultiHandle) {
            $this->curlMultiHandle = curl_multi_init();

            if (!defined('CURLPIPE_MULTIPLEX')) {
                define('CURLPIPE_MULTIPLEX', 2);
            }

            curl_multi_setopt($this->curlMultiHandle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
            curl_multi_setopt($this->curlMultiHandle, CURLMOPT_MAX_HOST_CONNECTIONS, $this->maxConcurrentConnections);
        }

        $mh = $this->curlMultiHandle;

        $i = 0;
        while (!empty($this->notifications) && $i++ < $this->nbConcurrentRequests) {
            $notification = array_pop($this->notifications);
            curl_multi_add_handle($mh, $this->prepareHandle($notification));
        }

        // Clear out curl handle buffer
        do {
            $execrun = curl_multi_exec($mh, $running);
        } while ($execrun === CURLM_CALL_MULTI_PERFORM);

        // Continue processing while we have active curl handles
        while ($running > 0 && $execrun === CURLM_OK) {
            // Block until data is available
            $select_fd = curl_multi_select($mh);
            // If select returns -1 while running, wait 250 microseconds before continuing
            // Using curl_multi_timeout would be better but it isn't available in PHP yet
            // https://php.net/manual/en/function.curl-multi-select.php#115381
            if ($running && $select_fd === -1) {
                usleep(250);
            }

            // Continue to wait for more data if needed
            do {
                $execrun = curl_multi_exec($mh, $running);
            } while ($execrun === CURLM_CALL_MULTI_PERFORM);

            // Start reading results
            while ($done = curl_multi_info_read($mh)) {
                $handle = $done['handle'];

                $result = curl_multi_getcontent($handle);

                // find out which token the response is about
                $token = curl_getinfo($handle, CURLINFO_PRIVATE);

                $responseParts = explode("\r\n\r\n", $result, 2);
                $headers = '';
                $body = '';
                if (isset($responseParts[0])) {
                    $headers = $responseParts[0];
                }
                if (isset($responseParts[1])) {
                    $body = $responseParts[1];
                }

                $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
                $responseCollection[] = new Response($statusCode, $headers, (string)$body, $token);
                curl_multi_remove_handle($mh, $handle);
                curl_close($handle);

                if (!empty($this->notifications)) {
                    $notification = array_pop($this->notifications);
                    curl_multi_add_handle($mh, $this->prepareHandle($notification));
                }
            }
        }

        if ($this->autoCloseConnections) {
            curl_multi_close($mh);
            $this->curlMultiHandle = null;
        }

        return $responseCollection;
    }
public function push ( ) : array { $ responseCollection = [ ] ; if ( ! $ this -> curlMultiHandle ) { $ this -> curlMultiHandle = curl_multi_init ( ) ; if ( ! defined ( 'CURLPIPE_MULTIPLEX' ) ) { define ( 'CURLPIPE_MULTIPLEX' , 2 ) ; } curl_multi_setopt ( $ this -> curlMultiHandle , CURLMOPT_PIPELINING , CURLPIPE_MULTIPLEX ) ; curl_multi_setopt ( $ this -> curlMultiHandle , CURLMOPT_MAX_HOST_CONNECTIONS , $ this -> maxConcurrentConnections ) ; } $ mh = $ this -> curlMultiHandle ; $ i = 0 ; while ( ! empty ( $ this -> notifications ) && $ i ++ < $ this -> nbConcurrentRequests ) { $ notification = array_pop ( $ this -> notifications ) ; curl_multi_add_handle ( $ mh , $ this -> prepareHandle ( $ notification ) ) ; } // Clear out curl handle buffer do { $ execrun = curl_multi_exec ( $ mh , $ running ) ; } while ( $ execrun === CURLM_CALL_MULTI_PERFORM ) ; // Continue processing while we have active curl handles while ( $ running > 0 && $ execrun === CURLM_OK ) { // Block until data is available $ select_fd = curl_multi_select ( $ mh ) ; // If select returns -1 while running, wait 250 microseconds before continuing // Using curl_multi_timeout would be better but it isn't available in PHP yet // https://php.net/manual/en/function.curl-multi-select.php#115381 if ( $ running && $ select_fd === - 1 ) { usleep ( 250 ) ; } // Continue to wait for more data if needed do { $ execrun = curl_multi_exec ( $ mh , $ running ) ; } while ( $ execrun === CURLM_CALL_MULTI_PERFORM ) ; // Start reading results while ( $ done = curl_multi_info_read ( $ mh ) ) { $ handle = $ done [ 'handle' ] ; $ result = curl_multi_getcontent ( $ handle ) ; // find out which token the response is about $ token = curl_getinfo ( $ handle , CURLINFO_PRIVATE ) ; $ responseParts = explode ( "\r\n\r\n" , $ result , 2 ) ; $ headers = '' ; $ body = '' ; if ( isset ( $ responseParts [ 0 ] ) ) { $ headers = $ responseParts [ 0 ] ; } if ( isset ( $ responseParts [ 1 ] ) ) { $ body = $ responseParts [ 1 ] ; } $ statusCode = curl_getinfo ( $ handle , CURLINFO_HTTP_CODE ) ; $ responseCollection [ ] = new Response ( $ statusCode , $ headers , ( string ) $ body , $ token ) ; curl_multi_remove_handle ( $ mh , $ handle ) ; curl_close ( $ handle ) ; if ( ! empty ( $ this -> notifications ) ) { $ notification = array_pop ( $ this -> notifications ) ; curl_multi_add_handle ( $ mh , $ this -> prepareHandle ( $ notification ) ) ; } } } if ( $ this -> autoCloseConnections ) { curl_multi_close ( $ mh ) ; $ this -> curlMultiHandle = null ; } return $ responseCollection ; }
Push notifications to APNs.

@return ApnsResponseInterface[]
Push notifications to APNs .