I have big DB function which has multiple lines like this
RAISE NOTICE \'some step completed\';
I want to get all this notices in my PHP ap
According to the libpq notice documentation "The default notice handling function prints the message on stderr, but the application can override this behavior by supplying its own handling function."
In your case the "application" (php itself) is overriding this behavior by specifying custom notice handler, called _php_pgsql_notice_handler:
Line #1367: PQsetNoticeProcessor(pgsql, _php_pgsql_notice_handler, (void*)Z_RESVAL_P(return_value));
That means that PostgreSQL notices are not propagated further into stderr, but are captured and processed by that handler.
In the handler itself (line #827) you can see that every time a notice is issued, php updates the variable holding it, and does not append the value to some array. Hence at the end only the last notice is present in that variable, obtainable by calling pg_last_notice()
.
So, it looks like it is not possible to obtain previous PostgreSQL notices from within PHP.
However, if you look further into the same notice handler, you would see that it is writing the notices to the error log, in case pgsql.ignore_notices = 0
, pgsql.log_notices = 1
and E_NOTICE
is included into the error_reporting. I guess with some php error handling functions juggling you will be able to obtain something.