草庐IT

try-catch-repeat

全部标签

php - Nginx clean urls,如何将文件夹重写为 try_files 的参数

我正在用PHP编写一个简单的CMS。页面(markdown文件)和图片是这样访问的(分别):example.org/?q=about.mdexample.org/?i=photo.jpg可选地,我想在Nginx中使用干净的URL,使相同的请求看起来像这样:example.org/aboutexample.org/photo.jpg我宁愿使用try_files而不是if和rewrite但是在试验了几个小时之后,我无法让它工作。location/{try_files$uri$uri//?q=$uri.md=404;}location~\.(gif|jpg|png)${try_files$u

php - 将 php 异常重新抛出到更高级别的 catch block 中

我正在尝试将异常从特定的catchblock传递到更通用的catchblock。但是它似乎没有用。当我尝试以下操作时出现500服务器错误。这可能吗?我知道有一些简单的解决方法,但是说“嘿,我不想处理这个错误,让我们用更通用的异常处理程序来处理吧!”这不是很正常吗?try{//somesoapstuff}catch(SoapFault$sf){thrownewException('SoapFault');}catch(Exception$e){echo$e->getMessage();} 最佳答案 从技术上讲,这就是您要查找的内容:t

php - slim 的 PHP : Only catch valid routes with middleware

我正在使用Slim编写RESTAPI。我编写了一个小型中间件来保护资源,因此只有经过身份验证的用户才能访问它们:resource=$resource;}publicfunctioncall(){//getareferencetoapplication$app=$this->app;//skiproutesthatareexceptionallyallowedwithoutanaccesstoken:$publicRoutes=["/","/login","/about"];if(in_array($app->request()->getPathInfo(),publicRoutes))

php - 失败时重试 try/catch

我尝试了几种不同的try/catch循环来尝试自动解决问题,但它们似乎总是导致软件死机。$doLoop=true;while($doLoop){try{//doathinginsertIntoDb($data);}catch(Exception$e){//tryagaininsertIntoDb($data);//writeerrortofilewriteError($e);}}这是我原来的try/catch。问题有时是MySQL服务器“消失”,我需要捕获该异常并不断重试,直到它恢复。我可以在这里更改什么以使其不断重试直到成功? 最佳答案

PHP Web 应用程序何时使用 try/catch

我正在使用PHP和CodeIgniter框架。我读过一些文章,指出使用try/catch方法是不好的做法。我了解在可能发生潜在错误时在开发中使用日志记录并让实际错误发生然后使用log_message('level','message')但是在部署时,您希望抑制和处理出现的任何错误。我是否应该使用try/catchblock,例如在...try{$this->data['important']=$this->Test_Model->do_something($data);if(empty(data['important'])){thrownewException('nodataretur

file-upload - PHP fatal error : Out of memory (allocated 80740352) (tried to allocate 12352 bytes) in

当用户在我的网站上上传图片时出现此错误。错误消息是“PHPfatalerror:/home中内存不足(已分配80740352)(已尝试分配12352字节)......”我该如何使用php.ini解决这个问题?这是我当前的上传php.ini设置upload_max_filesize=2000M;post_max_size=2000Mmax_file_uploads=8有什么想法我还需要添加什么来解决这个错误吗? 最佳答案 最佳memory_limit值取决于您对上传文件的处理方式。您是使用file_get_contents还是GD库将

php - fatal error : Allowed memory size of 67108864 bytes exhausted (tried to allocate 39 bytes) in xxx/xxx/xxx/xxx

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎不是关于aspecificprogrammingproblem,asoftwarealgorithm,orsoftwaretoolsprimarilyusedbyprogrammers的.如果您认为这个问题是关于anotherStackExchangesite的主题,您可以发表评论,说明问题可能在哪里得到解答。关闭6年前。Improvethisquestion我在godaddy托管了一个drupal网站。但现在有几天我正在与最奇怪的问题作斗争“fatalerror:允许的67108864字

PHP fatal error : I'm trying to implement a Form\AbstractType in my Symfony2 application

我收到以下错误:Fatalerror:DeclarationofBean\OauthServerBundle\Form\Type\AuthorizeFormType::buildForm()mustbecompatiblewithSymfony\Component\Form\FormTypeInterface::buildForm(Symfony\Component\Form\FormBuilderInterface$builder,array$options)insrc/Bean/OauthServerBundle/Form/Type/AuthorizeFormType.phponl

php - 如何在 symfony 中尝试 Catch

情况://trollCommand.php[...]foreach($trolltypesas$type){//$type=={"Frost","RandomBroken","Forest"}try{$output->writeln($type);$troll={"get".$type."TrollType"}();$output->writeln("TEST1");$troll->__load();$output->writeln("TEST2");}catch(EntityNotFoundException$e){$output->writeln("WARNING:TROLLENT

PHP try catch 异常

你好,我有这样的代码:try{//HereIcallmyexternalfunctiondo_some_work()}catch(Exception$e){}问题是:如果do_some_work()有问题并产生错误,这个trycatch会隐藏错误吗? 最佳答案 PHP中有两种类型的错误。有异常(exception),也有错误。try..catch将处理异常,但不会处理错误。为了捕获PHP错误,您需要使用set_error_handler()function.简化事情的一种方法可能是让set_error_handler()在遇到错误时