{
  "id": 10266663,
  "title": "02 - Persistent Memory Chat in PHP - History That Survives Restarts",
  "url": "https://urgent.news/2026/09/27/02-persistent-memory-chat-in-php-history-that-survives-restarts",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-27T18:03:14.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/hammrouni/02-persistent-memory-chat-in-php-history-that-survives-restarts-1h1e"
  },
  "original_language": "en",
  "account": "The article discusses the importance of persistent memory in chat applications built with PHP and the NanoAgent library. Sessions, which maintain chat history, disappear when a browser closes or a server restarts, making it necessary for memory to outlive the process. NanoAgent provides this feature by allowing developers to easily load and save conversation history for sessions.\n\nThe article highlights a simple one-line solution to implement persistent memory in NanoAgent: `$agent->setMemory(new FileMemory(__DIR__ . '/memory'), 'demo');`. This line sets up the memory driver, specifying the directory for storage and a session ID.\n\nThe article walks through an example that demonstrates how to wire up memory drivers, choose between different storage options, and set up an agent with long-term memory capabilities. It offers three built-in drivers: ArrayMemory (current process only), FileMemory (one JSON file per session), and PdoMemory (SQL table for multi-user apps). Each driver has its use cases, with FileMemory being ideal for small tools and PdoMemory being suitable for production environments.\n\nThe article also emphasizes the importance of choosing a secure session ID, as it determines which conversation is loaded. Ideally, session IDs should come from trusted sources, such as logged-in users or specific chat instances, rather than user input, which could lead to unauthorized access to other users' conversations.\n\nFinally, the article mentions that reseting the memory history is a simple one-line operation: `$agent->clearHistory();`. This command clears the in-process history and deletes the stored memory row/file, making it easy to manage conversation history in NanoAgent applications.",
  "summary": "Sessions are the easy answer for chat history, but they vanish when the browser closes or the server restarts. For anything that should remember - a support bot, a notes assistant, a shared conversation - you want history to outlive the process. In NanoAgent this is a first-class feature. You stop hand-rolling \"load the array, save the array\" yourself and attach a memory driver to the agent. It…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}