0

I am facing a problem, don't know either this is the server problem or in my coding. The problem is that when i make some changes(insert, update, delete) in database along with uploading images i get an error say [sitename] is currently unable to handle this request. But if i make any transaction without image uploading everything goes fine.

But there is another thing because of that i am confused is that my site has an admin panel also, if i upload images and data from user end every thing works but if i upload the data along with images gives an error. Don't know where the problem is. Either it is at server side problem or in my code.?

Following is the code that is being used at user end.

 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
            }
        } 
    }

And here is the code which is being used at backend, both are almost same.

        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.';
                    }
                }
            }
        }
    }

And here is the server error

Server Error Image

And Here are the server log errors

Log Errors

Waleed Ikhlaq
  • 39
  • 1
  • 8
  • It seems there is some memory limit issue and memory consumption by PHP is more than what it is allotted to. Check out this link. http://stackoverflow.com/questions/19508313/memory-limit-1024m-still-cannot-allocate-memory-couldnt-create-child-proce. – Wolverine Dec 17 '16 at 12:19
  • what type of memory disk storage or what? – Waleed Ikhlaq Dec 17 '16 at 12:21
  • can i check at what point it is taking much memory – Waleed Ikhlaq Dec 17 '16 at 12:23
  • plus this is not a wordpress site it is made in php – Waleed Ikhlaq Dec 17 '16 at 12:24
  • file size is only 10.4KB – Waleed Ikhlaq Dec 17 '16 at 12:25
  • Then, it should be physical memory. In PHP configuration file, there is a `memory_limit` option which is set 128 MB by default. If a script consumes more than this allotted memory, you may see a fatal error like "memory exhausted" or "couldn't create memory" or some other error. Maybe you need to increase the `memory_limit` either by modifying configuration file or by writing one line statement in your `index.php` file. – Wolverine Dec 17 '16 at 12:31
  • If you're going for configuration file method, find a line with `memory_limit`. Once you're done, change `memory_limit = 128M` to `memory_limit = 256M` or to some other memory limit you wish. The second method using one line statement in `index.php` is write `ini_set('memory_limit', '256M')`. This line should be at the very top of the file. Hope it resolves your issue. – Wolverine Dec 17 '16 at 12:35
  • It seems you're a shared hosting user. If you can't access configuration file, you may try `ini_set` approach. – Wolverine Dec 17 '16 at 12:37
  • i did ini_set but still same error now i went to netwrok tab and found failed to load response data what does this means now – Waleed Ikhlaq Dec 17 '16 at 12:40
  • Try setting `ini_set('display_errors', 1)` to enable the errors to be displayed. Now, it can be obvious seeing error directly on the page itself. – Wolverine Dec 17 '16 at 12:50
  • Hi i have just uploaded the same site on some other server and every thing worked successfully, this means that there is an issue in server settings .... ? – Waleed Ikhlaq Dec 17 '16 at 16:11
  • Yeah. Your shared web hosting provider has set the memory limit for PHP is very less than usual memory. That's why your script failed to process with more memory required. Never expect shared web hosting services to run large site. If you're running small site with no much traffic and also if you concern about cost, you could go for shared web hosting. Otherwise go for dedicated web hosting service which hosts your website in terms of a website per server. – Wolverine Dec 17 '16 at 16:12
  • i checked the memory usage its only 4.2 MB and i searched on google as well after reading comments i come to point that 4MB usage is ok no worry for that, but my other hosting panel is not dedicated as well, should i have to contact with service provider ... ? – Waleed Ikhlaq Dec 17 '16 at 17:10
  • Maybe you've seen memory usage in cPanel stats. It always looks normal unless you do some heavy task continuously and checking out cPanel stats at the same time and doing like that you might see memory usage taking effect considerably. And yeah, you need to contact your hosting service provider to have them resolve this issue. Hope you will get a resolution. – Wolverine Dec 17 '16 at 17:15

1 Answers1

0

Based on the error log, it looks like your server resource cannot handle your request anymore.

If physical memory for PHP is not enough to process your script then your web server cannot spawn new child process, thereby HTTP 500 error is encountered.

Here, you need to look over your physical memory if you're using physical server. If you're running in VM, try allocating more memory to VM.

Wolverine
  • 1,712
  • 1
  • 15
  • 18
weirdo
  • 334
  • 1
  • 10
  • He uses shared hosting. He can't increase the physical memory to VM unless he contacts the administrator of the shared hosting service. – Wolverine Dec 17 '16 at 12:48
  • i have checked my memory usage and i showing me 0% usage of available 1.4 GB this means that there is no issue with memory usage. – Waleed Ikhlaq Dec 17 '16 at 13:12
  • It's not about memory limit allotted to your VM. It's about memory limit allotted to PHP. Do one thing. To know how much memory is allotted to PHP, write `echo ini_get('memory_limit');` and check out what is printed on the page. Some shared web hosting service providers set PHP's memory limit lower than the actual which is `128M`. In your case, your web hosting provider might have set it very lower than `128M`. Write the code I mentioned above and check out how much they have allotted to PHP memory consumption. – Wolverine Dec 17 '16 at 15:52