Exemple #1
0
function runtask($url, $proxys)
{
    $md5 = md5($url);
    $result = false;
    $retry = 1;
    //进程开始,添加进程符号
    thread_count($md5);
    while ($result === false && $retry <= 10) {
        $proxy = $proxys[array_rand($proxys)];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_NOBODY, 30);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        $code = 0;
        if ($result != false) {
            $code = getCode($result);
        }
        if ($result != false && $code >= 200 && $code < 503) {
            //获取响应的头信息,统计业务已经足够了
            $header = format_header($result);
            $header["url"] = $url;
            $header["time"] = time();
            $header["date"] = date("Y-m-d\\TH:i:s\\Z", $header["time"]);
            list($header["ip"]) = explode(":", $proxy);
            //写入结果
            $dir = DIR . "cache/result/" . date("Ymd") . "/" . substr($md5, 0, 2);
            if (!is_dir($dir)) {
                mkdir($dir, 0777, true);
            }
            $file = sprintf("%s/%s.json", $dir, $md5);
            file_put_contents($file, json_encode($header) . "\n", FILE_APPEND | LOCK_EX);
        } else {
            $retry++;
            $result = false;
        }
    }
    //进程结束,删除进程符号
    thread_count($md5, true);
    return $result;
}
include_once '../credentials.php';
/**
 * Retrieve data from input fields
*/
$invoiceId = $_REQUEST['invoice-id'];
$reason = 'unsatisfied customer';
/**
 * Initialize handle and set options
*/
$url = "https://sandbox.plimus.com/services/2/orders/refund?invoiceId=" . $invoiceId . "&reason=" . $reason . "&cancelSubscriptions=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "{$credentials}");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
/**
 * Execute Curl call and extract header and body contant
*/
$result = curl_exec($ch);
$info = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
curl_close($ch);
$header = substr($result, 0, $info);
$body = substr($result, $info);
echo format_header($header, $body);
Exemple #3
0
function show_data_item($data_item)
{
    global $__status, $__config;
    //
    // Get the display version of the raw entry text
    //
    if ($__config['transform_text'] == 1) {
        $entry = transform_text($data_item['entry']);
    }
    if ($__status['page_type'] == 'searched_posts') {
        //
        // FIXME: This is not trivial. Figure out solution.
        //
        // $entry = highlight_search_terms ($__status['obs_q'], $entry);
    }
    //
    // Get the display version of the raw header text
    //
    $header = format_header($data_item);
    //
    // Display the post
    //
    ?>
  <div class='entry'>
    <div class='entry_header'>
      <?php 
    echo $header;
    ?>
    </div><!-- entry_header -->
    <hr class="header_body_separator">
    <div class='entry_body'>
      <?php 
    echo $entry;
    ?>
    </div><!-- entry_body -->
  </div><!-- entry -->
<?php 
    if (isset($__config['intensedebate_blog_acct'])) {
        if ($__status['page_type'] == 'single_post') {
            echo intense_debate_stub("{$__config['blog_url']}?post={$data_item['data_file']}");
        } else {
            echo "<span class=\"comments\"><a href=\"{$__config['blog_url']}?post={$data_item['data_file']}#respond\">Comments</a></span>";
        }
    }
    if (isset($__config['disqus_blog_acct'])) {
        if ($__status['page_type'] == 'single_post') {
            echo disqus_stub("{$__config['blog_url']}?post={$data_item['data_file']}");
        } else {
            echo "<span class=\"comments\"><a href=\"{$__config['blog_url']}?post={$data_item['data_file']}#disqus_thread\">Comments</a></span>";
        }
    }
}