Welcome Guest, Not a member yet? Register   Sign In
Parser is breaking my server
#1

[eluser]Robert May[/eluser]
Not entirely sure why, but this is the code I'm trying to run. The array_merge() works fine and outputs the correct array set. I think the problem has something to do with the content I'm loading via a view.

My Templater library:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Templater {

    var  $data_array = '';  
    
    function Build($data)
    {
        $CI =& get_instance();
        $CI->load->library('parser');
        
        // Provide defaults
        $data_array = array(
                        'website_name'    =>    'iMayges',
                        'page_title'    =>    'Page Not Found',
                        'subheading'    =>    'This page could not be found',
                        'content'        =>    'Please go back and try again, or report this error via the contact email address.',
                        'latest_blog_posts' => '',
                        'latest_gallery_image' => '',
                        'get_in_touch'        => '',
                        'copyright_notice'    => '',
                        
                    );
        
        // Should overwrite default values if they exist
        $data = array_merge($data_array, $data);
        
        // Build the latest blog posts etc here
        $data['latest_blog_posts']        =    '';
        $data['latest_gallery_image']    =    '';
        $data['get_in_touch']            =    '';
        
        $CI->parser->parse('site_template', $data);
    }
}

The relevant controller:
Code:
function index()
    {
        $this->session->keep_flashdata('refer');
        $content = $this->load->view('auth', '', TRUE);
        
        $data        = array(
                            'page_title'    =>    'Login',
                            'subheading'    =>    'Please login to continue',
                            'content'        =>    $content,
                        );
        $this->templater->build($data);
    }

The auth view:
Code:
<?
$attributes = array(    
                    'id' => 'loginform'    
                );
echo form_open('auth/login', $attributes);
?>
<ul id="loginform_list">
<li>Your username or email address: &lt;input type="text" name="author_name" id="login_textbox" maxlength="100" size="20" value=""/&gt;&lt;/li>
<li>Your password: &lt;input type="password" name="author_password" id="login_textbox" maxlength="100" size="20" value=""/&gt;&lt;/li>
<li>&lt;input type="submit" name="loginbutton" value="Login" id="loginbutton"/&gt;&lt;/li>
</ul>
&lt;/form&gt;

Basically, when you try to run it, the page won't load and the server appears to go down. Has it got something to do with how it's passing the content data, or the content data itself?

Many thanks for any advice.
#2

[eluser]TheFuzzy0ne[/eluser]
Please could you elaborate a bit more on "the server appears to go down"?
#3

[eluser]Robert May[/eluser]
I think it's taking either PHP or Apache down for about 20 minutes. But I can't be sure. Basically the page no longer loads, even if I reupload it without the parser enabled. It's now back up and I enabled a print_r() instead of the parser, which seems to work fine - leading me to believe it's the parser causing a fuss. Big Grin
#4

[eluser]TheFuzzy0ne[/eluser]
That's very strange indeed. Do you have a firewall installed on your server? In my limited experience, I've never known PHP or Apache to take a server down at all.
#5

[eluser]Robert May[/eluser]
This is on my Dreamhost server. Never had this sort of problem before. I'm wondering if I've somehow created an infinite loop or something. Is it safe for me to load the view into a variable if the view has PHP in it, and then run it through the parser?
Do I need to escape data before sticking it through the parser?
#6

[eluser]Robert May[/eluser]
Found one error in it, had told it to replace a variable that wasn't there. Not sure if that caused the issue, will test it now. Site's still running a bit weird.
#7

[eluser]TheFuzzy0ne[/eluser]
[quote author="Robert May" date="1239137070"]This is on my Dreamhost server. Never had this sort of problem before. I’m wondering if I’ve somehow created an infinite loop or something. Is it safe for me to load the view into a variable if the view has PHP in it, and then run it through the parser?
Do I need to escape data before sticking it through the parser?[/quote]

An infinite loop will most likely result in a stack overflow, so it's unlikely. Also, the maximum_execution_time would probably kick in before then. Even still, it should not take your server down, and if it did, you would probably be banned.


[quote author="Robert May" date="1239137070"]Found one error in it, had told it to replace a variable that wasn’t there. Not sure if that caused the issue, will test it now. Site’s still running a bit weird.[/quote]

If the worst comes to the worst, you could always try moving to a different template parser.
#8

[eluser]Robert May[/eluser]
Woo! That fixed it. I think an incorrect variable somehow messes it up quite badly. I might add a safeguard for that.
Seems to be working fine now!

Dreamhost usually don't overreact to errors like that. I believe each server is instanced, so they just reboot your instance for you.




Theme © iAndrew 2016 - Forum software by © MyBB