Home >Backend Development >PHP Tutorial >或者用到的php代码

或者用到的php代码

WBOY
WBOYOriginal
2016-06-13 10:29:371299browse

可能用到的php代码

1.延迟请求文件,模拟网速不好的时候的场景,代码地址如下:

https://gist.github.com/2650596

?

<?php/**** delay.php?f=file.js&t=100** 延时100毫秒加载file.js** *///得到扩展名function get_extend($file_name) {$extend =explode("." , $file_name);$va=count($extend)-1;return $extend[$va];} /*** begin*///cdn上存在的各种可能的文件类型$header = array(    'js' => 'Content-Type: application/x-javascript',    'css' => 'Content-Type: text/css',    'jpg' => 'Content-Type: image/jpg',    'gif' => 'Content-Type: image/gif',    'png' => 'Content-Type: image/png',    'jpeg' => 'Content-Type: image/jpeg',    'swf' => 'Content-Type: application/x-shockwave-flash');$filename = $_GET['f'];$R_files = file($_GET['f']);if(empty($type)) {$type = get_extend($filename);}header($header[$type]);ob_flush();flush();sleep($_GET['t']);//var_dump($R_files);echo join("\n",$R_files);?>

?适用方式:

把代码用php文件放到项目目录下,引用目标文件的时候,方式如下:

http://cdn/你的目录/delay.php?f=yourfile.js&t=100

?2.页面逻辑暂停,过一段时间再继续

ob_flush();flush();sleep($_GET['t']);

?sleep为php的内置函数,参数为时间,单位秒;要放到PHP后缀的文件下使用,或者要配置下在js文件下使用,或者js后缀的后面加上.php,如 xxx.js.php

?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn