Panel hooks logging extremely slow in 2.3.2

Hi, ive seen many issues about this. Most of them claimed that its solved so i am probably doing something wrong.

This takes ages in panel:

kirby()->hook(['panel.page.create', 'panel.page.update'], function($page) {
$file = kirby()->roots()->config() . DS . 'log.txt';
	  $current .= $page->uid() . "\n";
	  f::write($file, $current, true);
});

So what iam doing wrong? Kirby is updated to 2.3.2

I guess writing to file is not the most efficient thing to do but still it shouldn’t take this much time.

What would be more efficient way to log updated files? I need this log. Thx

Is it the issue that the loading bar at the top loads and loads forever? From which Kirby version did you upgrade?

There’s a typo in your code, maybe that solves it already:

kirby()->hook(['panel.page.create', 'panel.page.update'], function($page) {
	$file = kirby()->roots()->config() . DS . 'log.txt';
	$current = $page->uid() . "\n"; // <-- The dot before the = sign needs to be removed
	f::write($file, $current, true);
});

AAAAHH stupid typo. It seems it is solved.

Thank you!

Strangely i had same issue when i wanted to write straight to database.

Anyways THX!

It looks like this issue occurs when a hook produces some kind of output (a PHP warning/notice etc.).

Would it be possible to output these kind of messages in a modal to the user instead of hang the panel?

Output in hooks is not intended and this won’t work because the Panel frontend expects a JSON response. If there’s some kind of other output, it breaks the JSON.

I see. It’s a difficult to have a smooth debug experience with the hooks of today.

Would it be possible to return as html and convert the response on the PHP side? Then a simple validation could be made to see if it’s a JSON. If not, output an error message in a modal, if for example debug mode is true in the config.

That’s sounds a bit error-prone. What could work though is to capture output from the hooks using PHP’s output buffer and if that output is not empty tell the frontend to display it in a modal. Not sure how complex that is however.

1 Like

You just gave me a plugin idea. :slight_smile:

1 Like