0

I have a codeigniter project I am working on. When a certain flashdata gets added the site locks up for no apparent reason. I write some data to my database or remove it. Then according to a success of fail I set some flashdata and redirect to the appropriate page. There a gallery gets loaded in and the associated flashdata gets used. But 75% of the time it locks up for a couple seconds (between 10-15 on local testing).

I figured out it is the flashdata that is the issue and it happens as soon as I add it. Even when I remove the flashdata code out of the view the site locks up. Which by itself is strange to me. Even when it does not get used it locks up sometimes.

view part

<?php if($this->session->flashdata('msg')) : ?>
<div class="alert alert-success" role="alert">
    <?php echo $this->session->flashdata('msg'); ?>
</div>
<?php endif; ?>
<?php if($this->session->flashdata('error')) : ?>
<div class="alert alert-danger" role="alert">
    <?php echo $this->session->flashdata('error'); ?>
</div>
<?php endif; ?>

The controller code block

public function deleteVisitorLink($gallery_id)
{
    if(!$this->gallery_model->removeVisitorLink($gallery_id))
    {
        $this->logging->Log($this->session->userdata('id'), '550', 'Could not delete the visitor link for gallery ' . $gallery_id);
        $this->session->set_flashdata('error','Kon de link niet verwijderen.');
        $this->myRedirect();
    }
    else
    {
        $this->logging->Log($this->session->userdata('id'), '560', 'Visitor link deleted for gallery ' . $gallery_id);
        $this->session->set_flashdata('msg','De bezoekers link is verwijderd.');
    }

    redirect(base_url() . '/client/' . $gallery_id);
}

The myRedirect() is just a check and a standard redirect to client

I am trying to figure out why it is happening and what I might be able to do to fix this. Any tip or pointer is helpful as I am pretty new to coding.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • What session handler are you using - simple storage in the file system? That usually involves file looking, as long as any script instance is still working with the session. So if you have any other requests going on at the same time (AJAX background request, different page of the project loading in another tab, …), this might block other script instances from accessing the session. The solution to that usually is to call session_write_close as soon as possible in any longer-running script (not sure what the CI equivalent of that is when using $this->session, you’d have to go look that up.) – 04FS Apr 26 '19 at 08:00
  • $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = NULL; $config['sess_match_ip'] = FALSE; $config['sess_time_to_update'] = 300; $config['sess_regenerate_destroy'] = FALSE; The session write close does not see to help the issue. I just noticed the issue is not present when there are no images in de gallery – Pieter-Jan Casteels Apr 26 '19 at 08:45
  • Are you linking to these image files directly - or are those delivered via a script that uses the session as well? If the latter, try to close the session in that script as soon as possible (i.e., after you checked authorization for the image access(?), but before you return the actual image data to the client.) – 04FS Apr 26 '19 at 09:24
  • can something like $user_id = $this->session->userdata('id'); also cause that issue? – Pieter-Jan Casteels Apr 26 '19 at 09:30
  • *Anything* that accesses the session can cause it. As soon as any script instance picks up the session again, the session data file gets locked - until that script instance is done with the session, all other script instances trying to access the same session are kept waiting. – 04FS Apr 26 '19 at 09:39
  • I believe the issue might lay within the fact that it needs to remove the flashdata out of the session as soon as it is shown. And that that stop the rest from working for a small moment while it is getting other data. As that data is extensive it might choko up the system. Now the issue is how to solve it. – Pieter-Jan Casteels Apr 26 '19 at 11:22

1 Answers1

0

After some great insights by @04FS

I figured the issue light with the unsigning of the flashdata.

So instead i a now using tempdata. And i remove the tempdata at the end of the view.