本文整理汇总了PHP中w3_http_get函数的典型用法代码示例。如果您正苦于以下问题:PHP w3_http_get函数的具体用法?PHP w3_http_get怎么用?PHP w3_http_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了w3_http_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: external_event
/**
* Makes external event request
*
* @param string $type
* @param string $value
* @return array
*/
function external_event($type, $value)
{
$url = sprintf('%s?u=%s&tkn=%s&evnt_t=%s&evnt_v=%s', W3TC_CLOUDFLARE_EXTERNAL_EVENT_URL, urlencode($this->_config['email']), urlencode($this->_config['key']), urlencode($type), urlencode($value));
$response = w3_http_get($url, '', false);
if ($response) {
return json_decode($response);
}
return false;
}
示例2: external_event
/**
* Makes external event request
*
* @param string $type
* @param string $value
* @return array
*/
function external_event($type, $value)
{
require_once W3TC_INC_DIR . '/functions/http.php';
$url = sprintf('%s?u=%s&tkn=%s&evnt_t=%s&evnt_v=%s', W3TC_CLOUDFLARE_EXTERNAL_EVENT_URL, urlencode($this->_config['email']), urlencode($this->_config['key']), urlencode($type), urlencode($value));
$response = w3_http_get($url);
if (!is_wp_error($response)) {
return json_decode($response['body']);
}
return false;
}
示例3: w3_download
/**
* Downloads URL into a file
*
* @param string $url
* @param string $file
* @return boolean
*/
function w3_download($url, $file)
{
if (strpos($url, '//') === 0) {
$url = (w3_is_https() ? 'https:' : 'http:') . $url;
}
$response = w3_http_get($url);
if (!is_wp_error($response) && $response['response']['code'] == 200) {
return @file_put_contents($file, $response['body']);
}
return false;
}
示例4: _request
/**
* Make API request
*
* @param string $url
* @return string
*/
function _request($url)
{
require_once W3TC_INC_DIR . '/functions/http.php';
require_once W3TC_INC_DIR . '/functions/url.php';
$request_url = w3_url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key));
$response = w3_http_get($request_url);
if (!is_wp_error($response) && $response['response']['code'] == 200) {
return $response['body'];
}
return false;
}
示例5: test_rewrite
/**
* Perform rewrite test
*
* @param string $url
* @return boolean
*/
private function test_rewrite($url)
{
$key = sprintf('w3tc_rewrite_test_%s', substr(md5($url), 0, 16));
$result = get_transient($key);
if ($result === false) {
w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/http.php');
$response = w3_http_get($url);
$result = !is_wp_error($response) && $response['response']['code'] == 200 && trim($response['body']) == 'OK';
if ($result) {
set_transient($key, $result, 30);
} else {
$key_result = sprintf('w3tc_rewrite_test_result_%s', substr(md5($url), 0, 16));
set_transient($key_result, is_wp_error($response) ? $response->get_error_message() : implode(' ', $response['response']), 30);
}
}
return $result;
}
示例6: parse_sitemap
/**
* Parses sitemap
*
* @param string $url
* @return array
*/
function parse_sitemap($url)
{
require_once W3TC_INC_DIR . '/functions/http.php';
$urls = array();
$response = w3_http_get($url);
if (!is_wp_error($response) && $response['response']['code'] == 200) {
$url_matches = null;
$sitemap_matches = null;
if (preg_match_all('~<sitemap>(.*?)</sitemap>~is', $response['body'], $sitemap_matches)) {
$loc_matches = null;
foreach ($sitemap_matches[1] as $sitemap_match) {
if (preg_match('~<loc>(.*?)</loc>~is', $sitemap_match, $loc_matches)) {
$loc = trim($loc_matches[1]);
if ($loc) {
$urls = array_merge($urls, $this->parse_sitemap($loc));
}
}
}
} elseif (preg_match_all('~<url>(.*?)</url>~is', $response['body'], $url_matches)) {
$locs = array();
$loc_matches = null;
$priority_matches = null;
foreach ($url_matches[1] as $url_match) {
$loc = '';
$priority = 0;
if (preg_match('~<loc>(.*?)</loc>~is', $url_match, $loc_matches)) {
$loc = trim($loc_matches[1]);
}
if (preg_match('~<priority>(.*?)</priority>~is', $url_match, $priority_matches)) {
$priority = (double) trim($priority_matches[1]);
}
if ($loc && $priority) {
$locs[$loc] = $priority;
}
}
arsort($locs);
$urls = array_keys($locs);
}
}
return $urls;
}
示例7: w3_download
/**
* Downloads data to a file
*
* @param string $url
* @param string $file
* @return boolean
*/
function w3_download($url, $file)
{
if (strpos($url, '//') === 0) {
$url = (w3_is_https() ? 'https:' : 'http:') . $url;
}
$data = w3_http_get($url);
if ($data !== false) {
return @file_put_contents($file, $data);
}
return false;
}
示例8: _request
/**
* Make API request
*
* @param string $url
* @return string
*/
function _request($url)
{
$request_url = w3_url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key));
$json = w3_http_get($request_url);
return $json;
}
示例9: update_ip_ranges
/**
* Check
* @throws FilesystemOperationException
* @throws FileOperationException
*/
public function update_ip_ranges()
{
w3_require_once(W3TC_INC_DIR . '/functions/http.php');
$ip4_diff = $ip6_diff = false;
$response = w3_http_get(W3TC_CLOUDFLARE_IP4_URL);
$extensions_settings = $this->_config->get_array('extensions.settings', array());
if (!is_wp_error($response)) {
$ip4_data = $response['body'];
$ip4_data = explode("\n", $ip4_data);
$ip4_data_old = w3tc_get_extension_config('cloudflare', 'ips.ip4', $this->_config, array());
if ($ip4_diff = array_diff($ip4_data, $ip4_data_old)) {
$extensions_settings['cloudflare']['ips.ip4'] = $ip4_data;
$this->_config->set('extensions.settings', $extensions_settings);
}
}
$response = w3_http_get(W3TC_CLOUDFLARE_IP6_URL);
if (!is_wp_error($response)) {
$ip6_data = $response['body'];
$ip6_data = explode("\n", $ip6_data);
$ip6_data_old = w3tc_get_extension_config('cloudflare', 'ips.ip6', $this->_config, array());
if ($ip6_diff = array_diff($ip6_data, $ip6_data_old)) {
$extensions_settings['cloudflare']['ips.ip6'] = $ip6_data;
$this->_config->set('extensions.settings', $extensions_settings);
}
}
if ($ip4_diff || $ip6_diff) {
try {
$this->_config->save();
$this->_config->refresh_cache();
} catch (Exception $ex) {
}
}
}
示例10: prime_post
/**
* Makes get requests to url specific to a post, its permalink
* @param $post_id
* @return boolean returns true on success
*/
public function prime_post($post_id)
{
/** @var $purges W3_PageUrls */
$purges = w3_instance('W3_PageUrls');
$post_urls = $purges->get_post_urls($post_id);
foreach ($post_urls as $url) {
$result = w3_http_get($url);
if (is_wp_error($result)) {
return false;
}
}
return true;
}
示例11: get_files_minify
/**
* Exports min files to CDN
*
* @return array
*/
function get_files_minify()
{
$files = array();
if (W3TC_PHP5 && $this->_config->get_boolean('minify.rewrite') && (!$this->_config->get_boolean('minify.auto') || w3_is_cdn_mirror($this->_config->get_string('cdn.engine')))) {
require_once W3TC_INC_DIR . '/functions/http.php';
$minify =& w3_instance('W3_Plugin_Minify');
$document_root = w3_get_document_root();
$site_root = w3_get_site_root();
$minify_root = w3_path(W3TC_CACHE_FILE_MINIFY_DIR);
$minify_path = ltrim(str_replace($site_root, rtrim(w3_get_site_path(), '/'), $minify_root), '/');
$urls = $minify->get_urls();
if ($this->_config->get_string('minify.engine') == 'file') {
foreach ($urls as $url) {
w3_http_get($url);
}
$files = $this->search_files($minify_root, $minify_path, '*.css;*.js');
} else {
foreach ($urls as $url) {
$file = w3_normalize_file_minify($url);
$file = w3_translate_file($file);
if (!w3_is_url($file)) {
$file = $document_root . '/' . $file;
$file = ltrim(str_replace($minify_root, '', $file), '/');
$dir = dirname($file);
if ($dir) {
w3_mkdir($dir, 0777, $minify_root);
}
if (w3_download($url, $minify_root . '/' . $file) !== false) {
$files[] = $minify_path . '/' . $file;
}
}
}
}
}
return $files;
}
示例12: get_theme_recommendations
/**
* Returns theme recommendations
*
* @param string $theme_name
* @return array
*/
function get_theme_recommendations($theme_name)
{
$urls = $this->get_theme_urls($theme_name);
$js_groups = array();
$css_groups = array();
@set_time_limit($this->_config->get_integer('timelimit.minify_recommendations'));
foreach ($urls as $template => $url) {
/**
* Append theme identifier
*/
$url .= (strstr($url, '?') !== false ? '&' : '?') . 'w3tc_theme=' . urlencode($theme_name);
/**
* If preview mode enabled append w3tc_preview
*/
if (w3_is_preview_config()) {
$url .= '&w3tc_preview=1';
}
/**
* Get page contents
* Don't check response code for 404 template
*/
$content = w3_http_get($url, null, $template != '404');
if ($content) {
$js_files = $this->get_recommendations_js($content);
$css_files = $this->get_recommendations_css($content);
$js_groups[$template] = $js_files;
$css_groups[$template] = $css_files;
}
}
$js_groups = $this->_get_theme_recommendations($js_groups);
$css_groups = $this->_get_theme_recommendations($css_groups);
$recommendations = array($js_groups, $css_groups);
return $recommendations;
}
示例13: prime_post
/**
* Makes get requests to url specific to a post, its permalink
* @param $post_id
* @return boolean returns true on success
*/
public function prime_post($post_id)
{
/** @var $purges W3_SharedPageUrls */
$purges = w3_instance('W3_SharedPageUrls');
$post_urls = $purges->get_post_urls($post_id);
/**
* Make HTTP requests and prime cache
*/
w3_require_once(W3TC_INC_DIR . '/functions/http.php');
w3_require_once(W3TC_INC_DIR . '/functions/url.php');
foreach ($post_urls as $url) {
$result = w3_http_get($url, array('user-agent' => ''));
if (is_wp_error($result)) {
return false;
}
}
return true;
}
示例14: update_ip_ranges
/**
* Check
* @throws FilesystemOperationException
* @throws FileOperationException
*/
public function update_ip_ranges()
{
w3_require_once(W3TC_INC_DIR . '/functions/http.php');
$ip4_diff = $ip6_diff = false;
$config_master = new W3_Config(true);
$response = w3_http_get(W3TC_CLOUDFLARE_IP4_URL);
if (!is_wp_error($response)) {
$ip4_data = $response['body'];
$ip4_data = explode("\n", $ip4_data);
$ip4_data_old = $this->_config->get_array('cloudflare.ips.ip4');
if ($ip4_diff = array_diff($ip4_data, $ip4_data_old)) {
$config_master->set('cloudflare.ips.ip4', $ip4_data);
}
}
$response = w3_http_get(W3TC_CLOUDFLARE_IP6_URL);
if (!is_wp_error($response)) {
$ip6_data = $response['body'];
$ip6_data = explode("\n", $ip6_data);
$ip6_data_old = $this->_config->get_array('cloudflare.ips.ip6');
if ($ip6_diff = array_diff($ip6_data, $ip6_data_old)) {
$config_master->set('cloudflare.ips.ip6', $ip6_data);
}
}
if ($ip4_diff || $ip6_diff) {
$config_master->save();
}
}
示例15: test_rewrite
/**
* Perform rewrite test
*
* @param string $url
* @return boolean
*/
function test_rewrite($url)
{
$key = sprintf('w3tc_rewrite_test_%s', substr(md5($url), 0, 16));
$result = get_transient($key);
if ($result === false) {
$response = w3_http_get($url);
$result = !is_nxt_error($response) && $response['response']['code'] == 200 && trim($response['body']) == 'OK';
if ($result) {
set_transient($key, $result, 30);
}
}
return $result;
}