I think the root of the problem is my understanding of string handling. serialize($_SESSION) does the same thing. My session file goes on for 5kb, but when I output session_encode() to the log or to a database, it cuts off after about 100 bytes.
$s = session_encode();
$n = strlen($s);
error_log("Session ($n): $s");
I get:
Session (5948): return_url|s:30:"https://solution-locale/Moneys";complete|s:0:"";basket|O:15:"SolutionUBasket":22:{s:13:
When I try writing the value to the database (pg_execute()--that's a prepared statement) I get the same problem. But when I do a bin2hex(), I learn that after that last ":" there's a null character (0x00).
So clearly the problem is string handling, and I'm not doing it right.
And the db-writing code is the following:
pg_prepare($this->getCnx(), $token, $sql);
pg_execute($this->getCnx(), $token, $values);
$sql is:
UPDATE "solution_ubasket_temp" SET ("session_id", "session", "id") = ($1, $2, $3) WHERE "id"=$4"
$values is just an array. strlen() operations on it confirms that all 5kb get into the session member.
The update goes ahead without error messages, but the "session" field gets cut off just like the in the debug.
select length(session), * from solution_ubasket_temp
confirms that "session" gets cutoff after 105 bytes.
The "session" column is a text but changing it to a bytea didn't help.
select octet_length(session), * from solution_ubasket_temp
confirms that.
I'm running PHP 5.6 on Debian 8.5.
error_logfunction:Warning error_log() is not binary safe. message will be truncated by null character.(php.net/manual/en/function.error-log.php)var_dump("Session ($n): $s");??NULbyte. That is in itself not a problem that requires fixing. Only: 1)error_login particular cannot correctly deal withNULbytes, which is why your debugging method fails; 2) Postgres can deal withNULbytes just fine if you handle them correctly. You'll have to show us what exactly you're doing withpg_executefor us to help you with that part of the problem.