Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I have the following code working on a WordPress plugin. But there's no WP issue, the matter is:
can I trust @get_headers to perform most of times?

public function enqueue()
{
 $http = is_ssl() ? 'https:' : 'http:';
 $url = "$http//netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.csss";
 if( $this->get_http_response_code( $url ) ) {
 my_load_external_script();
 }
 else {
 my_load_local_script();
 }
}
/**
 * Problem with getting header, return false
 *
 * otherwise return if headers are 200 or not
 *
 * @param $url string
 * @return boolean
 */
private function get_http_response_code( $url ) 
{
 $headers = @get_headers( $url );
 if( !$headers )
 return false;
 
 return substr( $headers[0], 9, 3 ) === '200';
 }

The current requirement for running WordPress is PHP 5.2.4 or greater. As I understand it, there's no 100% guarantee, but for having a plugin running in the wild I'd prefer the less problematic path. I've checked the following Stack Overflow Q&A's, but haven't come to any conclusion:

I have the following code working on a WordPress plugin. But there's no WP issue, the matter is:
can I trust @get_headers to perform most of times?

public function enqueue()
{
 $http = is_ssl() ? 'https:' : 'http:';
 $url = "$http//netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.csss";
 if( $this->get_http_response_code( $url ) ) {
 my_load_external_script();
 }
 else {
 my_load_local_script();
 }
}
/**
 * Problem with getting header, return false
 *
 * otherwise return if headers are 200 or not
 *
 * @param $url string
 * @return boolean
 */
private function get_http_response_code( $url ) 
{
 $headers = @get_headers( $url );
 if( !$headers )
 return false;
 
 return substr( $headers[0], 9, 3 ) === '200';
 }

The current requirement for running WordPress is PHP 5.2.4 or greater. As I understand it, there's no 100% guarantee, but for having a plugin running in the wild I'd prefer the less problematic path. I've checked the following Stack Overflow Q&A's, but haven't come to any conclusion:

I have the following code working on a WordPress plugin. But there's no WP issue, the matter is:
can I trust @get_headers to perform most of times?

public function enqueue()
{
 $http = is_ssl() ? 'https:' : 'http:';
 $url = "$http//netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.csss";
 if( $this->get_http_response_code( $url ) ) {
 my_load_external_script();
 }
 else {
 my_load_local_script();
 }
}
/**
 * Problem with getting header, return false
 *
 * otherwise return if headers are 200 or not
 *
 * @param $url string
 * @return boolean
 */
private function get_http_response_code( $url ) 
{
 $headers = @get_headers( $url );
 if( !$headers )
 return false;
 
 return substr( $headers[0], 9, 3 ) === '200';
 }

The current requirement for running WordPress is PHP 5.2.4 or greater. As I understand it, there's no 100% guarantee, but for having a plugin running in the wild I'd prefer the less problematic path. I've checked the following Stack Overflow Q&A's, but haven't come to any conclusion:

Source Link
brasofilo
  • 469
  • 3
  • 19

Checking if a CDN file is available

I have the following code working on a WordPress plugin. But there's no WP issue, the matter is:
can I trust @get_headers to perform most of times?

public function enqueue()
{
 $http = is_ssl() ? 'https:' : 'http:';
 $url = "$http//netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.csss";
 if( $this->get_http_response_code( $url ) ) {
 my_load_external_script();
 }
 else {
 my_load_local_script();
 }
}
/**
 * Problem with getting header, return false
 *
 * otherwise return if headers are 200 or not
 *
 * @param $url string
 * @return boolean
 */
private function get_http_response_code( $url ) 
{
 $headers = @get_headers( $url );
 if( !$headers )
 return false;
 
 return substr( $headers[0], 9, 3 ) === '200';
 }

The current requirement for running WordPress is PHP 5.2.4 or greater. As I understand it, there's no 100% guarantee, but for having a plugin running in the wild I'd prefer the less problematic path. I've checked the following Stack Overflow Q&A's, but haven't come to any conclusion:

lang-php

AltStyle によって変換されたページ (->オリジナル) /