当前位置: 首页>>代码示例>>PHP>>正文


PHP FreePBX::Curl方法代码示例

本文整理汇总了PHP中FreePBX::Curl方法的典型用法代码示例。如果您正苦于以下问题:PHP FreePBX::Curl方法的具体用法?PHP FreePBX::Curl怎么用?PHP FreePBX::Curl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FreePBX的用法示例。


在下文中一共展示了FreePBX::Curl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: file_get_contents_url

/** like file_get_contents designed to work with url only, will try
 * wget if fails or if MODULEADMINWGET set to true. If it detects
 * failure, will set MODULEADMINWGET to true for future improvements.
 *
 * @param   mixed   url to be fetches or array of multiple urls to try
 * @return  mixed   content of first successful url, boolean false if it failed.
 */
function file_get_contents_url($file_url)
{
    global $amp_conf;
    $contents = '';
    if (!is_array($file_url)) {
        $file_url = array($file_url);
    }
    foreach ($file_url as $fn) {
        if (!$amp_conf['MODULEADMINWGET']) {
            ini_set('user_agent', 'Wget/1.10.2 (Red Hat modified)');
            $contents = @file_get_contents($fn);
        }
        if (empty($contents)) {
            $fn2 = str_replace('&', '\\&', $fn);
            FreePBX::Curl()->setEnvVariables();
            exec("wget --tries=1 --timeout=30 -O - {$fn2} 2>> /dev/null", $data_arr, $retcode);
            if ($retcode) {
                // if server isn't available for some reason should return non-zero
                // so we return and we don't set the flag below
                freepbx_log(FPBX_LOG_ERROR, sprintf(_('Failed to get remote file, mirror site may be down: %s'), $fn));
                continue;
                // We are here if contents were blank. It's possible that whatever we were getting were suppose to be blank
                // so we only auto set the WGET var if we received something so as to not false trigger. If there are issues
                // with content filters that this is designed to get around, we will eventually get a non-empty file which
                // will trigger this for now and the future.
            } elseif (!empty($data_arr) && !$amp_conf['MODULEADMINWGET']) {
                $freepbx_conf =& freepbx_conf::create();
                $freepbx_conf->set_conf_values(array('MODULEADMINWGET' => true), true);
                $nt =& notifications::create($db);
                $text = sprintf(_("Forced %s to true"), 'MODULEADMINWGET');
                $extext = sprintf(_("The system detected a problem trying to access external server data and changed internal setting %s (Use wget For Module Admin) to true, see the tooltip in Advanced Settings for more details."), 'MODULEADMINWGET');
                $nt->add_warning('freepbx', 'MODULEADMINWGET', $text, $extext, '', false, true);
            }
            $contents = implode("\n", $data_arr);
            return $contents;
        } else {
            return $contents;
        }
        // we get here if all wget's fail
        return false;
    }
}
开发者ID:lidl,项目名称:framework,代码行数:49,代码来源:utility.functions.php

示例2: url_get_contents

 function url_get_contents($url, $request, $verb = 'get', $params = array())
 {
     $params['sv'] = 2;
     global $amp_conf;
     $verb = strtolower($verb);
     $contents = null;
     if (!$amp_conf['MODULEADMINWGET']) {
         $pest = FreePBX::Curl()->pest($url);
         try {
             $contents = $pest->{$verb}($url . $request, $params);
             if (isset($pest->last_headers['x-regenerate-id'])) {
                 $this->_regenerate_unique_id();
             }
             return $contents;
         } catch (Exception $e) {
             freepbx_log(FPBX_LOG_ERROR, sprintf(_('Failed to get remote file, error was:'), (string) $e->getMessage()));
         }
     }
     $fn = $url . $request;
     if (empty($contents)) {
         $fn2 = str_replace('&', '\\&', $fn);
         $p = !empty($params) ? "--post-data '" . http_build_query($params) . "'" : "";
         FreePBX::Curl()->setEnvVariables();
         exec("wget --tries=1 --timeout=30 {$p} -O - {$fn2} 2> /dev/null", $data_arr, $retcode);
         if ($retcode) {
             // if server isn't available for some reason should return non-zero
             // so we return and we don't set the flag below
             freepbx_log(FPBX_LOG_ERROR, sprintf(_('Failed to get remote file, mirror site may be down: %s'), $fn));
             // We are here if contents were blank. It's possible that whatever we were getting were suppose to be blank
             // so we only auto set the WGET var if we received something so as to not false trigger. If there are issues
             // with content filters that this is designed to get around, we will eventually get a non-empty file which
             // will trigger this for now and the future.
             return null;
         } elseif (!empty($data_arr) && !$amp_conf['MODULEADMINWGET']) {
             $freepbx_conf = freepbx_conf::create();
             $freepbx_conf->set_conf_values(array('MODULEADMINWGET' => true), true);
             $nt = notifications::create($db);
             $text = sprintf(_("Forced %s to true"), 'MODULEADMINWGET');
             $extext = sprintf(_("The system detected a problem trying to access external server data and changed internal setting %s (Use wget For Module Admin) to true, see the tooltip in Advanced Settings for more details."), 'MODULEADMINWGET');
             $nt->add_warning('freepbx', 'MODULEADMINWGET', $text, $extext, '', false, true);
         }
         $headers = get_headers_assoc($fn2);
         if (isset($headers['x-regenerate-id'])) {
             $this->_regenerate_unique_id();
         }
         $contents = implode("\n", $data_arr);
         return $contents;
     }
 }
开发者ID:lidl,项目名称:framework,代码行数:49,代码来源:modulefunctions.class.php

示例3: getRemoteFile

 /**
  * Retrieve a remote file
  * Stores file into memory
  * @param  string $path The full path to said file
  * @return string       binary representation of file
  */
 private function getRemoteFile($path)
 {
     $modulef =& \module_functions::create();
     $contents = null;
     $mirrors = $modulef->generate_remote_urls($path, true);
     $params = $mirrors['options'];
     $params['sv'] = 2;
     foreach ($mirrors['mirrors'] as $url) {
         set_time_limit($this->maxTimeLimit);
         try {
             $pest = \FreePBX::Curl()->pest($url);
             $contents = $pest->post($url . $path, $params);
             if (isset($pest->last_headers['x-regenerate-id'])) {
                 $modulef->_regenerate_unique_id();
             }
             if (!empty($contents)) {
                 return $contents;
             }
         } catch (\Exception $e) {
             freepbx_log(FPBX_LOG_ERROR, sprintf(_('Failed to get remote file, error was:'), (string) $e->getMessage()));
         }
     }
 }
开发者ID:lidl,项目名称:soundlang,代码行数:29,代码来源:Soundlang.class.php

示例4: runGPG

 /**
  * Actually run GPG
  * @param string Params to pass to gpg
  * @param fd File Descriptor to feed to stdin of gpg
  * @return array returns assoc array consisting of (array)status, (string)stdout, (string)stderr and (int)exitcode
  */
 public function runGPG($params, $stdin = null)
 {
     // Ensure our proxy settings are set, if needed.
     \FreePBX::Curl()->setEnvVariables();
     $fds = array(array("file", "/dev/null", "r"), array("pipe", "w"), array("pipe", "w"), array("pipe", "w"));
     // If we need to send stuff to stdin, then do it!
     if ($stdin) {
         $fds[0] = $stdin;
     }
     $webuser = \FreePBX::Freepbx_conf()->get('AMPASTERISKWEBUSER');
     $home = $this->getGpgLocation();
     // We need to ensure that our environment variables are sane.
     // Luckily, we know just the right things to say...
     if (!isset($this->gpgenv)) {
         $this->gpgenv['PATH'] = "/bin:/usr/bin";
         $this->gpgenv['USER'] = $webuser;
         $this->gpgenv['HOME'] = sys_get_temp_dir();
         $this->gpgenv['SHELL'] = "/bin/bash";
     }
     $homedir = "--homedir {$home}";
     $cmd = $this->gpg . " {$homedir} " . $this->gpgopts . " --status-fd 3 {$params}";
     $proc = proc_open($cmd, $fds, $pipes, "/tmp", $this->gpgenv);
     if (!is_resource($proc)) {
         // Unable to start!
         freepbx_log(FPBX_LOG_FATAL, "Tried to run command and failed: " . $cmd);
         throw new \Exception(sprintf(_("Unable to start GPG, the command was: [%s]"), $cmd));
     }
     // Wait $timeout seconds for it to finish.
     $tmp = null;
     $r = array($pipes[3]);
     if (!stream_select($r, $tmp, $tmp, $this->timeout)) {
         freepbx_log(FPBX_LOG_FATAL, "Tried to run command and failed: " . $cmd);
         throw new \RuntimeException(sprintf(_("GPG took too long to run the command: [%s]"), $cmd));
     }
     // We grab stdout and stderr first, as the status fd won't
     // have completed and closed until those FDs are emptied.
     $retarr['stdout'] = stream_get_contents($pipes[1]);
     $retarr['stderr'] = stream_get_contents($pipes[2]);
     $status = explode("\n", stream_get_contents($pipes[3]));
     array_pop($status);
     // Remove trailing blank line
     $retarr['status'] = $status;
     $exitcode = proc_close($proc);
     $retarr['exitcode'] = $exitcode;
     return $retarr;
 }
开发者ID:nriendeau,项目名称:framework,代码行数:52,代码来源:GPG.class.php


注:本文中的FreePBX::Curl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。