1、使用延时来实现每N秒执行,View是Zend Framewor

本文实例讲述了php实现有趣的人品测试程序。分享给大家供大家参考。具体实现方法如下:

linux crontab 命令,最小的执行时间是一分钟。如需要在小于一分钟内重复执行,可以有两个方法实现。

本文实例讲述了Zend Framework教程之视图组件Zend_View用法。分享给大家供大家参考,具体如下:

算算你的人品BY冷枫哥哥.btn{background:#fff; color:#005681;border-width:1px;padding-left:15px;padding-right:15px;vertical-align:middle}.input{border:solid 1px #B6D9E3;padding:2px 0px 2px 1px;font-size:1.0em;vertical-align:middle}





程序制作:冷枫哥哥©1.01".$name."";for($i = 0;$i < strlen{$a=$a+ord;}if{//此处可以换上你的名字~你懂得~OO~$shuzi=100;}else{$shuzi=%100;}echo $name."的得分是".$shuzi."";function getValue{if  { echo "你一定不是人吧?怎么一点人品都没有?!";} elseif && { echo "算了,跟你没什么人品好谈的...";} else if  &&  { echo "是我不好...不应该跟你谈人品问题的..."; } else if  &&  { echo "杀过人没有?放过火没有?你应该无恶不做吧?"; } else if  &&  { echo "你貌似应该三岁就偷看隔壁大妈洗澡的吧..."; } else if  &&  { echo "你的人品之低下实在让人惊讶啊..."; } else if  &&  { echo "你的人品太差了。你应该有干坏事的嗜好吧?"; } else if  &&  { echo "你的人品真差!肯定经常做偷鸡摸狗的事..."; } else if  &&  { echo "你拥有如此差的人品请经常祈求佛祖保佑你吧..."; } else if  &&  { echo "老实交待..那些论坛上面经常出现的偷拍照是不是你的杰作?"; } else if  &&  { echo "你随地大小便之类的事没少干吧?"; } else if  &&  { echo "你的人品太差了..稍不小心就会去干坏事了吧?"; } else if  &&  { echo "你的人品很差了..要时刻克制住做坏事的冲动哦.."; } else if  &&  { echo "你的人品比较差了..要好好的约束自己啊.."; } else if  &&  { echo "你的人品勉勉强强..要自己好自为之.."; } else if  &&  { echo "有你这样的人品算是不错了.."; } else if  &&  { echo "你有较好的人品..继续保持.."; } else if  &&  { echo "你的人品不错..应该一表人才吧?"; } else if  &&  { echo "你的人品真好..做好事应该是你的爱好吧.."; } else if  &&  { echo "你的人品太好了..你就是当代活雷锋啊..."; } else if  &&  { echo "你是世人的榜样!"; } else if  { echo "天啦!你不是人!你是神!!!"; } else { echo "你的人品竟然负溢出了...我对你无语.."; }}getValue;/*$fp=fopen;$date=date;$content="|".$date."|".$name."|".$shuzi."rn";fwrite;fclose;*/}if;?>

1、使用延时来实现每N秒执行

Zend_View是Zend Framework的视图组件,MVC中的视图层。 Zend_View也是应用的直接对用户展示的页面。这里介绍一下Zend_View的实现类,以及如何和Controller结合在一起的。

希望本文所述对大家的php程序设计有所帮助。

创建一个php做执行动作,非常简单,就是把当前时间写入log。

View的实现

<?php
file_put_contents('/home/fdipzone/php/crontab/run.log', date('Y-m-d H:i:s')."rn", FILE_APPEND);
?>

Zend_View的实现主要是通过如下目录的类实现:

crontab -e 输入以下语句,然后 :wq 保存退出。

root@coder-671T-M:/library/Zend# tree | grep View.php│ └── View/├── View.php

* * * * * php /home/fdipzone/php/crontab/tolog.php
* * * * * sleep 10; php /home/fdipzone/php/crontab/tolog.php
* * * * * sleep 20; php /home/fdipzone/php/crontab/tolog.php
* * *美高梅游戏网站登录, * * sleep 30; php /home/fdipzone/php/crontab/tolog.php
* * * * * sleep 40; php /home/fdipzone/php/crontab/tolog.php
* * * *美高梅棋牌官网, * sleep 50; php /home/fdipzone/php/crontab/tolog.php使用 tail -f 查看执行情况,可以见到log每10秒被写入一条记录。

root@coder-671T-M:/library/Zend/View# tree.├── Abstract.php├── Exception.php├── Helper│ ├── Abstract.php│ ├── Action.php│ ├── BaseUrl.php│ ├── Currency.php│ ├── Cycle.php│ ├── DeclareVars.php│ ├── Doctype.php│ ├── Fieldset.php│ ├── FormButton.php│ ├── FormCheckbox.php│ ├── FormElement.php│ ├── FormErrors.php│ ├── FormFile.php│ ├── FormHidden.php│ ├── FormImage.php│ ├── FormLabel.php│ ├── FormMultiCheckbox.php│ ├── FormNote.php│ ├── FormPassword.php│ ├── Form.php│ ├── FormRadio.php│ ├── FormReset.php│ ├── FormSelect.php│ ├── FormSubmit.php│ ├── FormTextarea.php│ ├── FormText.php│ ├── Gravatar.php│ ├── HeadLink.php│ ├── HeadMeta.php│ ├── HeadScript.php│ ├── HeadStyle.php│ ├── HeadTitle.php│ ├── HtmlElement.php│ ├── HtmlFlash.php│ ├── HtmlList.php│ ├── HtmlObject.php│ ├── HtmlPage.php│ ├── HtmlQuicktime.php│ ├── InlineScript.php│ ├── Interface.php│ ├── Json.php│ ├── Layout.php│ ├── Navigation│ │ ├── Breadcrumbs.php│ │ ├── HelperAbstract.php│ │ ├── Helper.php│ │ ├── Links.php│ │ ├── Menu.php│ │ └── Sitemap.php│ ├── Navigation.php│ ├── PaginationControl.php│ ├── Partial│ │ └── Exception.php│ ├── PartialLoop.php│ ├── Partial.php│ ├── Placeholder│ │ ├── Container│ │ │ ├── Abstract.php│ │ │ ├── Exception.php│ │ │ └── Standalone.php│ │ ├── Container.php│ │ ├── Registry│ │ │ └── Exception.php│ │ └── Registry.php│ ├── Placeholder.php│ ├── RenderToPlaceholder.php│ ├── ServerUrl.php│ ├── TinySrc.php│ ├── Translate.php│ ├── Url.php│ └── UserAgent.php├── Interface.php└── Stream.php

fdipzone@ubuntu:~$ tail -f /home/fdipzone/php/crontab/run.log
2014-03-31 21:47:01
2014-03-31 21:47:11
2014-03-31 21:47:21
2014-03-31 21:47:31
2014-03-31 21:47:41
2014-03-31 21:47:51
2014-03-31 21:48:01
原理:通过延时方法 sleep N  来实现每N秒执行。

6 directories, 70 files

注意:

Zend_View和Zend_Controller的整合

60必须能整除间隔的秒数(没有余数),例如间隔的秒数是2,4,6,10,12等。

主要在Zend_Controller_Action类中,

如果间隔的秒数太少,例如2秒执行一次,这样就需要在cr

/** * Initialize View object * * Initializes {@link $view} if not otherwise a Zend_View_Interface. * * If {@link $view} is not otherwise set, instantiates a new Zend_View * object, using the 'views' subdirectory at the same level as the * controller directory for the current module as the base directory. * It uses this to set the following: * - script path = views/scripts/ * - helper path = views/helpers/ * - filter path = views/filters/ * * @return Zend_View_Interface * @throws Zend_Controller_Exception if base view directory does not exist */ public function initView() { if (!$this->getInvokeArg && $this->_helper->hasHelper { return $this->view; } require_once 'Zend/View/Interface.php'; if  && ($this->view instanceof Zend_View_Interface)) { return $this->view; } $request = $this->getRequest(); $module = $request->getModuleName(); $dirs = $this->getFrontController()->getControllerDirectory || !isset { $module = $this->getFrontController->getDefaultModule(); } $baseDir = dirname . DIRECTORY_SEPARATOR . 'views'; if (!file_exists || !is_dir { require_once 'Zend/Controller/Exception.php'; throw new Zend_Controller_Exception('Missing base view directory ; } require_once 'Zend/View.php'; $this->view = new Zend_View(array('basePath' => $baseDir)); return $this->view; } /** * Render a view * * Renders a view. By default, views are found in the view script path as * /.phtml. You may change the script suffix by * resetting {@link $viewSuffix}. You may omit the controller directory * prefix by specifying boolean true for $noController. * * By default, the rendered contents are appended to the response. You may * specify the named body content segment to set by specifying a $name. * * @see Zend_Controller_Response_Abstract::appendBody() * @param string|null $action Defaults to action registered in request object * @param string|null $name Response object named path segment to use; defaults to null * @param bool $noController Defaults to false; i.e. use controller name as subdir in which to search for view script * @return void */ public function render($action = null, $name = null, $noController = false) { if (!$this->getInvokeArg && $this->_helper->hasHelper { return $this->_helper->viewRenderer->render($action, $name, $noController); } $view = $this->initView(); $script = $this->getViewScript($action, $noController); $this->getResponse()->appendBody( $view->render; } /** * Render a given view script * * Similar to {@link render()}, this method renders a view script. Unlike render(), * however, it does not autodetermine the view script via {@link getViewScript()}, * but instead renders the script passed to it. Use this if you know the * exact view script name and path you wish to use, or if using paths that do not * conform to the spec defined with getViewScript(). * * By default, the rendered contents are appended to the response. You may * specify the named body content segment to set by specifying a $name. * * @param string $script * @param string $name * @return void */ public function renderScript($script, $name = null) { if (!$this->getInvokeArg && $this->_helper->hasHelper { return $this->_helper->viewRenderer->renderScript; } $view = $this->initView(); $this->getResponse()->appendBody( $view->render; }

本文由美高梅游戏网站登录发布于美高梅棋牌游戏,转载请注明出处:1、使用延时来实现每N秒执行,View是Zend Framewor

您可能还会对下面的文章感兴趣: