Coding question - flush()

I'm trying to understand the purpose of line 97 in scripts/notify.php
  if ($dir) { flush(); chdir($dir); }

Specifically, why does it call flush? I know the call has been there for a long time, at least since 2015. Yet, recently on my site pmwiki.php has started reporting "headers already sent" errors. I tested headers_sent() before and after line 97, and it's false before the line and true after. Therefore it must be flush that sends premature headers before pmwiki.php. I couldn't find out what is being flushed, apparently nothing: I set ob_start() when pmwiki.php starts, and read ob_get_contents() right before line 97 but the buffer is always empty. My question is why does it flush? I don't get it. I'm trying to understand what could go wrong on my site, and cause that line to be executed too early. Thank you. --SteP February 09, 2020, at 11:46 PM

Hmm, thinking about this a bit more, perhaps I'm looking in the wrong place. If I get it, line 97 can only be executed when the page is posted, and flush is merely signifying that the page headers are really done, as they are. Then more output could be sent except for headers. So maybe some other recipe is setting headers and that's why pmwiki.php complains. I will check this hypothesis. It must be a recipe that calls register_shutdown_function... --SteP February 10, 2020, at 06:40 AM

It is more likely a space or other character, or a byte order mark before the leading "<?php" or after the last "?>" of a script, see Troubleshooting#headers. --Petko February 10, 2020, at 06:48 AM

Thanks. I did check for BOMs already (and didn't have files with BOM before). I need to check the "?>", though. Did I interpret the significance of that flush correctly? --SteP February 10, 2020, at 06:52 AM

Line 97 can run in many cases, not only when a page is posted, but also when a page is read. NotifyUpdate stores a new entry when a page is posted, and when any page is read it reads the stored entries in case the time has come to send the messages. They are run after all other processing was done (register_shutdown_function) but can take some time to finish, especially if you have many pages, or many users. The server buffers the output until the script runs, that's why we use the function flush() to send not only the headers but the page content to the browser, so that the visitor may see the page content faster. If your buffer is empty, either the regular processing lead to redirect, or you probably call this function before, rather than after regular page processing, which is not what is intended. --Petko February 10, 2020, at 10:04 AM

Thank you so much for explaining how this works. --SteP February 10, 2020, at 11:02 AM

Hi, I have been trying to get this working but have been unsuccessful. I have done the following Created a SiteAdmin.NotifyList page with the content
In the local/config.php file I have added these
$EnableNotify = 1; # enable notify
$NotifyFrom = '';
$NotifyDelay = 60;
# include the change summary and link to the page's history in the message
$NotifyItemFmt =
" * {\$FullName} . . . \$PostTime by {\$Author}
\n Summary: {\$LastModifiedSummary}\n {\$PageUrl}?action=diff";
$NotifyBodyFmt = "Changed items:\n\n" . '$NotifyItems' . "\n\n Best regards...";
$NotifySubjectFmt = "Page Modified";
$NotifyList[] = '';
ini_set('SMTP','organisation_smtp_server_name @');

What am I missing here

-Kannan 15th Jan, 2020

First ask your systems administrator, or review the documentation at your hosting provider, if the server is configured correctly to send e-mail (the mail() function in PHP). Then try with only $EnableNotify = 1; and what you have in the page SiteAdmin.NotifyList. Messages are sent not on the first edit, but sometimes later, when a page is requested for reading -- keep browsing/reading your wiki. Check if the (hidden) file wiki.d/.notifylist gets updated (increases) after you edit and then gets emptied (happens when PmWiki sends the mails). After a while check your mailbox, including the Spam folders. If you must send the mail via the SMTP server of your company you can try Cookbook:SMTPMail (the `curl` utility needs to be installed on the server and to have internet access -- I use it for GMail). Enable the ini_set lines only if your administrator has approved those. After you get the feature to work, then you can try modifying the subject, body. A custom From: header which may cause the mail to be rejected or caught by the spam filters (for this to work you may need to edit the SPF fields in the domain's DNS zone). --Petko January 15, 2020, at 07:47 PM

Thank you will surely try it

How to check why notify does not send a mail?

~PKHG 30 oct 2014

Is there a simple way for users to sign up for email notifications without having to place the Administrator in the loop?

I know you can have the Admin point SiteAdmin.NotifyList to a wikitrail for each user, but that still requires an Admin to set up each individual user...



Hi i been using PMWIKI for a while but no matter what im not able to find or at least create a SiteAdmin.NotifyList page, could anybody provide more clear instructions regarding how to use this feature? i really need to have it up and running.

thank you.


P.S. and if the site admins delete this post you can reply to my personal email, thanks again.

This page doesn't exist in a new installation - and you need an Administrator password to create it. See PasswordsAdmin about how to set an administrator password -- then you can link to [[SiteAdmin.NotifyList]] and create the page on your wiki. --Petko February 02, 2010, at 06:44 PM

Thank you from me too, I have the same problem.

But I do not understand: WHERE should one create a link to [[SiteAdmin.NotifyList]]? In pmwiki.php ?


From any page, like your WikiSandbox -- just create a link, then click on it to edit the NotifyList page. Or in the browser's address bar, go to then edit the empty page. --Petko February 04, 2010, at 03:01 AM

Hey Petko thanks for your prompt answer , i have one more question, what about if i would like to use my exchange server to send emails instead of a regular mail server with smtp? another question is how does this Notify script access the server when sending emails? in my case we are Using Exchange 6.0

thanks again

I don't know about Exchange -- PmWiki is using the standard PHP mail() function to send notifications -- and it is normally configured by your hosting provider. If you install and run the server, you need to read the documentation and configure it. --Petko February 09, 2010, at 01:04 PM

I made it work with exchange but it does not send messages the way i have the script set up (first change delay 5 minutes, 24 hours for second notification) it does take a long time to send the email but it does work i tried (SMTP),(your server IP), it might have something to do with exchange i guess. thought you guys might be interested.


Is it possible to make the Notify function show the changed/edited content inside the email? and not that you have to click on the link for "Recent Changes" ? Thank you very much


Another thing. I can get the notify to work when i notify an email from my own domain (f.e. I send it from to, but if I set the sent from my domain and try to send the notification to Gmail, the email never comes.

Any clue why?


This is a talk page for improving PmWiki.Notify.