【问题标题】:Server is currently unable to handle this request服务器当前无法处理此请求
【发布时间】:2017-05-03 01:53:46
【问题描述】:

我遇到了一个问题,不知道这是服务器问题还是我的编码问题。问题是,当我在数据库中进行一些更改(插入、更新、删除)以及上传图像时,我收到一条错误消息,说 [站点名称] 当前无法处理此请求。但是,如果我在没有上传图片的情况下进行任何交易,一切都会好起来的。

但我感到困惑的另一件事是,我的网站也有一个管理面板,如果我从用户端上传图像和数据,一切正常,但如果我将数据与图像一起上传,则会出现错误。不知道问题出在哪里。是在服务器端问题还是在我的代码中。?

以下是用户端正在使用的代码。

 public function partner_register() {

        $date = date('Y/m/d');
        $this -> form_validation -> set_rules('contact', 'person contact', 'required|xss_clean');
        $this -> form_validation -> set_rules('company', 'company name', 'required|xss_clean');
        $this -> form_validation -> set_rules('ph', 'phone', 'required|xss_clean');
        $this -> form_validation -> set_rules('email', 'email', 'required|valid_email|is_unique[partner.email]|max_length[100]|xss_clean');

        $contact = $this -> input -> post('contact');
        $email = $this -> input -> post('email');
        $phone = $this -> input -> post('ph');
        $name = $this -> input -> post('company');
        $brand = $this -> input -> post('brand');

        if($brand == null or empty($brand) or $brand == "") {
            ?>  <script> alert('Select atleast one brand');
                        window.location = "<?php echo base_url('register'); ?>"; 
                </script>
            <?php
        }

        else if ($this -> form_validation -> run() == FALSE) {
            ?>  <script> alert('Email already exists. Please try new email.');
                        window.location = "<?php echo base_url(); ?>"; 
                </script>
            <?php
        }
        else {
            $info = $this -> Parts_Model -> partner_register([
                'contact'   =>  $contact,
                'email'     =>  $email,
                'company'   =>  $name,
                'phone'     =>  $phone,
                'reg_date'     =>  $date,
            ]);
            if($info) {
                foreach($brand as $key => $value) {
                    $brands = $this -> Parts_Model -> partner_brands([
                        'partner_id'   =>  $info,
                        'brands'   =>  $value,
                    ]);
                }
                if($brands) {
                    ?> <script> alert('Subscription successfull.'); window.location = "<?php echo base_url('register'); ?>"; </script> <?php
                }
            }
            else {
                ?> <script> alert('Subscription failed.'); window.location = "<?php echo base_url('register'); ?>"; </script> <?php
            }
        } 
    }

这是后端使用的代码,两者几乎相同。

        public function add_ads() {

        $this -> header_template();
        $this -> form_validation -> set_rules('link', 'ad link', 'required|xss_clean');
        $this -> form_validation -> set_rules('schedule', 'start date', 'required|xss_clean');
        $this -> form_validation -> set_rules('end_schedule', 'end date', 'required|xss_clean');

        $link = $this -> input -> post('link');
        $schedule = $this -> input -> post('schedule');
        $end_schedule = $this -> input -> post('end_schedule');

        $config['upload_path'] = 'ads/';
        $config['allowed_types'] = 'jpg|jpeg|png';
        $config['encrypt_name'] = true;
        $this -> load -> library('upload', $config);

        if($this -> form_validation -> run() == false) {
            echo validation_errors();
        }
        else {
            if(!$this -> upload -> do_upload('ad')) {
                ?> <script> alert('<?php echo $this -> upload -> display_errors(); ?>'); window.location = "<?php echo base_url('dashboard/ads'); ?>"; </script> <?php
            }
            else {
                $data = $this -> upload -> data();
                if($data['file_name'] and $data['full_path']) {
                    $file_name = $data['file_name'];
                    $file_path = $config['upload_path'].$file_name;
                    $info = $this -> Dashboard_Model -> add_ads([
                        'add_link'         =>  $link,
                        'schedule'         =>  $schedule,
                        'end_schedule'         =>  $end_schedule,
                        'ads'              =>  $file_path,
                    ]);
                    if($info) {
                    ?> 
                        <script> alert('Added Successfully.'); window.location = "<?php echo base_url('dashboard/ads'); ?>"; </script> 
                    <?php 
                    }
                    else {
                        echo 'Error! While adding brands.';
                    }
                }
            }
        }
    }

这是服务器错误

Server Error Image

这是服务器日志错误

Log Errors

【问题讨论】:

  • 似乎存在一些内存限制问题,PHP 的内存消耗超过了分配给的内存。看看这个链接。 stackoverflow.com/questions/19508313/….
  • 什么类型的内存磁盘存储或什么?
  • 我可以检查一下它在什么时候占用了很多内存
  • 另外,这不是一个 wordpress 网站,它是用 php 制作的
  • 文件大小只有10.4KB

标签: php codeigniter


【解决方案1】:

根据错误日志,您的服务器资源似乎无法再处理您的请求。

如果 PHP 的物理内存不足以处理您的脚本,那么您的 Web 服务器将无法生成新的子进程,从而遇到 HTTP 500 错误。

在这里,如果您使用物理服务器,则需要查看您的物理内存。如果您在 VM 中运行,请尝试为 VM 分配更多内存。

【讨论】:

  • 他使用共享主机。除非他联系共享托管服务的管理员,否则他无法增加 VM 的物理内存。
  • 我检查了我的内存使用情况,显示可用 1.4 GB 的使用率为 0%,这意味着内存使用没有问题。
  • 这与分配给 VM 的内存限制无关。这是关于分配给 PHP 的内存限制。做一件事。要知道分配给 PHP 的内存量,请写 echo ini_get('memory_limit'); 并查看页面上打印的内容。一些共享网络托管服务提供商将 PHP 的内存限制设置为低于实际的 128M。在您的情况下,您的网络托管服务提供商可能将其设置为比128M 低得多。编写我上面提到的代码,并检查它们分配给 PHP 内存消耗的数量。
猜你喜欢
  • 2022-07-05
  • 2016-09-01
  • 2016-07-11
  • 1970-01-01
  • 2016-06-09
  • 2020-09-16
  • 2021-11-16
  • 2021-06-30
相关资源
最近更新 更多