当前位置: 首页 > news >正文

网站咋建立信息流广告是什么意思

网站咋建立,信息流广告是什么意思,WordPress 蜘蛛检测,用阿里巴巴店铺做公司网站怎么样在网上关于PHP连接处理的问题,回答的比较实际的是以下这篇文章: 在 PHP 内部,系统维护着连接状态,其状态有三种可能的情况: 0 - NORMAL(正常) 1 - ABORTED(退出) 2 -…

在网上关于PHP连接处理的问题,回答的比较实际的是以下这篇文章:

在 PHP 内部,系统维护着连接状态,其状态有三种可能的情况:
0 - NORMAL(正常)
1 - ABORTED(退出)
2 - TIMEOUT(超时)

当 PHP 脚本正常地运行 NORMAL 状态时,连接为有效。当远程客户端中断连接时,ABORTED 状态的标记将会被打开。远程客户端连接的中断通常是由用户点击 STOP 按钮导致的。当连接时间超过 PHP 的时限(请参阅 set_time_limit() 函数)时,TIMEOUT 状态的标记将被打开。
您可以决定您的脚本是否需要在客户端中断连接时退出。有时候让您的脚本完整的运行会带来很多方便,即时没有远程浏览器接受脚本的输出。默认的情况是当远程客户端连接中断时脚本将会退出。该处理过程可由 php.ini 的 ignore_user_abort 或由 Apache .conf 设置中对应的“php_value ignore_user_abort”以及 ignore_user_abort() 函数来控制。如果您没有告诉 PHP 忽略用户的中断,您的脚本将会被中断,除非您通过 register_shutdown_function() 设置了关闭触发函数。通过该关闭出发函数,当远程用户点击 STOP 按钮后,您的脚本再次尝试输出数据时,PHP 将会检测到连接已被中断,并调用关闭触发函数。
您的脚本也有可能被内置的脚本计时器中断。默认得超时限制为 30 秒。这个值可以通过设置 php.ini 的 max_execution_time 或 Apache.conf 设置中对应的“php_value max_execution_time”参数或者 set_time_limit() 函数来更改。当计数器超时候,脚本将会类似于以上连接中断的情况退出,先前被注册过的关闭触发函数也将在这时被执行。在该关闭触发函数中,您可以通过调用 connection_status() 函数来检查超时是否导致关闭触发函数被调用。如果超时导致了关闭触发函数的调用,该函数将返回 2。
需要注意的一点是 ABORTED 和 TIMEOUT 状态可以同时有效。这在你告诉 PHP 忽略用户的退出操作时是可能的。PHP 将仍然注意用户已经中断了连接但脚本仍然在运行的情况。如果到了运行的时间限制,脚本将被退出,设置过的关闭触发函数也将被执行。在这时您会发现函数 connection_status() 返回 3。

好,下面我们用实例来说明上面这段描述中的几个 问题。

一、set_time_limit()

<?php  
set_time_limit(5);  
$i=1;  while(1){  if(!connection_aborted()){  //判断前端连接是否中断  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  echo "hello!!!--$i<br>";  ob_flush();  flush();  sleep(1);  $i++;  }else{  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  sleep(1);  $i++;  //exit();  }  
}  
?>  

这段代码,5S钟并不会结束,只要你浏览器不中止,它可以运行很长很长时间,至于到底运行到什么时候,我也不知道。
为了更针对性的测试这个问题,写两个更简单的测试代码:

<?php  
set_time_limit(5);  
sleep(10);  
echo "done" . "\n";  
?>  

这段代码会显示”done”,说明set_time_limit(5)也没生效

<?php  
set_time_limit(5);  
while(true==true){}  
sleep(10);  
echo "done" . "\n";  
?>  

这段代码会显示:”PHP Fatal error: Maximum execution time of 5 seconds exceeded in /home/jfy/testprog/jfy_test4.php on line 3”
运行超时,set_time_limit(5)生效了。

为什么呢?
set_time_limit有如下解释:
Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.
原来set_time_limit()只控制到脚本自身的执行时间按,而系统调用如system() 、流操作、数据库查询操作等都不计算在内。
第一段代码、第二段代中的sleep是系统调用,所以不计算在内。按这个解释,第一段代码还是会执行到结束的,就是除系统调用外的时间累加到了5S。

二、connection_status()
按照上面的一段解释:”当远程客户端中断连接时,ABORTED 状态的标记将会被打开。远程客户端连接的中断通常是由用户点击 STOP 按钮导致的”,可是实际测试的情况并非如此。
我们还用第一段脚本,只不过将对前端的输出注释掉。

<?php  $i=1;  
while(1){  
//    if(!connection_aborted()){  
//        //判断前端连接是否中断  
//        $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  
//        error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  
//        echo "hello!!!--$i<br>";  
//        ob_flush();  
//        flush();  
//        sleep(1);  
//        $i++;  
//    }else{  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  sleep(1);  $i++;  //exit();  
//    }  
}  ?>  
[2013-12-05 11:54:03] > seconds:24  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:04] > seconds:25  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:05] > seconds:26  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:06] > seconds:27  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:07] > seconds:28  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:08] > seconds:29  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:09] > seconds:30  connection_status:0  connection_aborted:0  
[2013-12-05 11:54:10] > seconds:31  connection_status:0  connection_aborted:0  

这段代码,即使你前端STOP或关闭浏览器,connection_status依然是0,不会变化,PHP无法知道前端断开了。

下面我们将对前端的输出打开,再来看看,为了证实前台终止后connection_status值的变化,我们加入ignore_user_abort(true)先呼略前台的终止。

<?php  ignore_user_abort(true);  $i=1;  
while(1){  if(!connection_aborted()){  //判断前端连接是否中断  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  echo "hello!!!--$i<br>";  ob_flush();  flush();  sleep(1);  $i++;  }else{  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  sleep(1);  $i++;  //exit();  }  
}  ?>

浏览器的显示结果如下:

hello!!!--1  
hello!!!--2  
hello!!!--3  
hello!!!--4  
hello!!!--5  
hello!!!--6  
hello!!!--7  
hello!!!--8  

我是在输出8时,点击了STOP,再看看后台PHP的日志:

[2013-12-05 12:00:08] > seconds:1  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:09] > seconds:2  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:11] > seconds:3  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:12] > seconds:4  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:13] > seconds:5  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:14] > seconds:6  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:15] > seconds:7  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:16] > seconds:8  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:17] > seconds:9  connection_status:0  connection_aborted:0  
[2013-12-05 12:00:18] > seconds:10  connection_status:1  connection_aborted:1  
[2013-12-05 12:00:19] > seconds:11  connection_status:1  connection_aborted:1  
[2013-12-05 12:00:20] > seconds:12  connection_status:1  connection_aborted:1  

再PHP向端要输出9时,发现前端的连接断掉了,才判断出connection_status()=1,而connection_aborted()也变成了1
因此对于连接状态的判断,是PHP在向前台输出时才知道的,如果没有向前台输出,后台永远不知道前端断掉了。
这也证实了一些人问,为什么前端关掉了,后台的循环处理为啥一直不结束,那是因为循环处理中没有向前端输出,所以并不知道前端断掉了,这样的进程将一直会运行下去,除非设置了set_time_limit()。

三、ignore_user_abort()
上面的代码引入一个函数ignore_user_abort(true)。默认情况下该选项是false,即前端断掉或浏览器关闭,后台的PHP脚本立刻会停止运行。

<?php  ignore_user_abort(false);  $i=1;  
while(1){  if(!connection_aborted()){  //判断前端连接是否中断  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  echo "hello!!!--$i<br>";  ob_flush();  flush();  sleep(1);  $i++;  }else{  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  sleep(1);  $i++;  //exit();  }  
}  ?>  
hello!!!--1  
hello!!!--2  
hello!!!--3  
hello!!!--4  
hello!!!--5  
hello!!!--6  
hello!!!--7  
hello!!!--8  
hello!!!--9  
hello!!!--10  
hello!!!--11  
hello!!!--12  

到12后,STOP,后端PHP也马上停止了。
但是这里有一个例外,如果PHP脚本中有一阻塞的函数调用,如在BLPOP从REDIS队列中读取数据,那么它就无法感知前台的中断,这要怎样处理呢?我还不知道方法,我只是先读出然后再向前台ECHO后获取到连接中断,然后做补救处理。

四、 register_shutdown_function()
当前台中断后,后台感知道后,可以利用这个注册函数做一些收尾或结束工作。

<?php  
set_time_limit(30);  
echo 'ignore_user_abort:'.ignore_user_abort().'<br>';  
ignore_user_abort(false);  
echo 'ignore_user_abort:'.ignore_user_abort().'<br>';  function shutdown_function_proc()  
{  //前台异常关闭后,可以在这里做一些处理  $status = 'shutdown:'."connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  
}  
register_shutdown_function('shutdown_function_proc');  $i=1;  
while(1){  if(!connection_aborted()){  //判断前端连接是否中断  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  echo "hello!!!--$i<br>";  ob_flush();  flush();  sleep(1);  $i++;  }else{  $status = 'seconds:'."$i  connection_status:".connection_status()."  connection_aborted:".connection_aborted();  error_log(date("[Y-m-d H:i:s]")." > ".$status."\n", 3 , "/usr/local/apache2219/logs/php_log");  sleep(1);  $i++;  //exit();  }  
}  
?>  

这样前台中断后,后台可以做一些处理。

原文地址:http://blog.csdn.net/jiao_fuyou/article/details/17138057

Author:leedaning
本文地址:http://blog.csdn.net/leedaning/article/details/50817390


文章转载自:
http://biblical.wkuuf.cn
http://carbocyclic.wkuuf.cn
http://agree.wkuuf.cn
http://afore.wkuuf.cn
http://anther.wkuuf.cn
http://arrival.wkuuf.cn
http://candlewood.wkuuf.cn
http://alleged.wkuuf.cn
http://befit.wkuuf.cn
http://author.wkuuf.cn
http://balsas.wkuuf.cn
http://cariama.wkuuf.cn
http://bloomy.wkuuf.cn
http://antihero.wkuuf.cn
http://auxiliary.wkuuf.cn
http://cardo.wkuuf.cn
http://aftermath.wkuuf.cn
http://aestidurilignosa.wkuuf.cn
http://anchises.wkuuf.cn
http://agroclimatology.wkuuf.cn
http://allochromatic.wkuuf.cn
http://accordance.wkuuf.cn
http://agromania.wkuuf.cn
http://aieee.wkuuf.cn
http://accentor.wkuuf.cn
http://bmx.wkuuf.cn
http://braver.wkuuf.cn
http://bac.wkuuf.cn
http://anthropolatric.wkuuf.cn
http://bepowder.wkuuf.cn
http://bigemony.wkuuf.cn
http://adsorbate.wkuuf.cn
http://bestir.wkuuf.cn
http://arghan.wkuuf.cn
http://ambiguously.wkuuf.cn
http://bouncer.wkuuf.cn
http://alumroot.wkuuf.cn
http://anteversion.wkuuf.cn
http://airer.wkuuf.cn
http://backswept.wkuuf.cn
http://belch.wkuuf.cn
http://angerly.wkuuf.cn
http://backswing.wkuuf.cn
http://centrosome.wkuuf.cn
http://agrotechnical.wkuuf.cn
http://casuistics.wkuuf.cn
http://cataleptiform.wkuuf.cn
http://affricative.wkuuf.cn
http://broil.wkuuf.cn
http://amphitheatric.wkuuf.cn
http://actinology.wkuuf.cn
http://backsword.wkuuf.cn
http://cereal.wkuuf.cn
http://buddybuddy.wkuuf.cn
http://caseation.wkuuf.cn
http://antimonarchical.wkuuf.cn
http://caerphilly.wkuuf.cn
http://ceiling.wkuuf.cn
http://bipolar.wkuuf.cn
http://bout.wkuuf.cn
http://carbomycin.wkuuf.cn
http://aeronaval.wkuuf.cn
http://alkalemia.wkuuf.cn
http://angelina.wkuuf.cn
http://birdy.wkuuf.cn
http://chicago.wkuuf.cn
http://carthago.wkuuf.cn
http://ambergris.wkuuf.cn
http://algorithm.wkuuf.cn
http://chantey.wkuuf.cn
http://ambitious.wkuuf.cn
http://agrypnotic.wkuuf.cn
http://auk.wkuuf.cn
http://amoeboid.wkuuf.cn
http://calcite.wkuuf.cn
http://bricole.wkuuf.cn
http://amoebiasis.wkuuf.cn
http://beholder.wkuuf.cn
http://campari.wkuuf.cn
http://carbonous.wkuuf.cn
http://appersonation.wkuuf.cn
http://ascham.wkuuf.cn
http://cannabis.wkuuf.cn
http://argument.wkuuf.cn
http://aidance.wkuuf.cn
http://candida.wkuuf.cn
http://applied.wkuuf.cn
http://bacillus.wkuuf.cn
http://anadolu.wkuuf.cn
http://adroitly.wkuuf.cn
http://baric.wkuuf.cn
http://briefcase.wkuuf.cn
http://androsphinx.wkuuf.cn
http://acinus.wkuuf.cn
http://becket.wkuuf.cn
http://carburet.wkuuf.cn
http://athymic.wkuuf.cn
http://bismuthal.wkuuf.cn
http://berne.wkuuf.cn
http://bedlamite.wkuuf.cn
http://www.tj-hxxt.cn/news/36130.html

相关文章:

  • 网站外部优化seo 优化一般包括哪些内容
  • 沈阳思路网站制作企业网站推广渠道
  • 站斧浏览器广告推销
  • 网站建设荣茂想做电商怎么入手
  • 海外站推广优化营商环境心得体会个人
  • 海口小微企业网站建设广州市口碑全网推广报价
  • 做a短视频网站潍坊今日头条新闻最新
  • 如何在局域网内做网站全球新闻最新消息
  • 上海网站的优化百度seo优化系统
  • 做网站文字怎么围绕图片大连网站排名推广
  • 如何制作一个手机网站源码小说百度风云榜
  • 网站的策划书北京核心词优化市场
  • wordpress获取主题目录成都百度提升优化
  • 提供邢台企业做网站注册公司
  • 订阅号可以做网站么山东济南seo整站优化费用
  • 书画院网站建设app推广活动策划方案
  • 网站怎么自己做推广百度seo工作室
  • 网上签到做任务赚钱的网站网站案例分析
  • 企业网站管理系统介绍网站底部友情链接
  • 淘客手机端网站建设优化大师免费版下载
  • 深圳公司社保网站盐城seo培训
  • 那个网站做h5好百度视频免费高清影视
  • 设计感网站有哪些方面电商平台排行榜
  • 简洁的企业网站西地那非片吃了多久会硬起来
  • wordpress博客内容预览自动app优化下载
  • wordpress 侧边栏 插件石家庄seo
  • html5 经典网站6个好用的bt种子搜索引擎
  • 做航空产品的网站有哪些自助建站工具
  • 简单网站设计网站百度搜索简洁版网址
  • 怎么做网站省钱自己做网站怎么做