What Does "write failed: No space left on device" Mean?
When you encounter Warning: Unknown(): write failed: No space left on device (28) in your web server logs, it is almost never a coding error. The application itself hasn't crashed; the operating system has simply run out of room to store new data. This specific message often appears alongside session-related warnings like Failed to write session data (files). If your session.save_path is configured to /tmp, the kernel is telling you that the temporary filesystem has hit its capacity limit or maximum inode usage.
The distinction between "no space" and "no inodes" is critical for troubleshooting. A standard disk full error occurs when the partition's data blocks are exhausted. However, if your /tmp directory contains thousands of small filesâsuch as uncleaned session files, log fragments, or temporary uploadsâthe filesystem can fill up even if there is still gigabytes of free space available. This happens because each file requires an inode entry, and once that table is full, the system cannot create new files regardless of remaining storage.
To diagnose the issue immediately, you need to inspect both the disk usage and the inode count. Run the following command on your server to see how much space and how many inodes are utilized:
df -h /tmp
If the Use% column shows 100%, you have a data capacity issue. However, if the IUse% column is at 100% while the disk usage looks low, your problem is inode exhaustion. In both scenarios, the web server cannot write session files, cache data, or upload temporary resources until space is reclaimed.
The most common culprit for this specific error in a PHP environment is orphaned session files. When a user's session expires or the script crashes before properly deleting the session file, it can remain in /tmp. Over time, these stale files accumulate. You can identify and remove them safely by checking the directory permissions and age:
find /tmp/sessions -type f -atime +7 -delete
Note: Adjust the path to match your actual session.save_path configuration and ensure you have the correct permissions to delete files in that directory.
Another frequent cause is log file bloat. If your application or the web server (Nginx/Apache) writes verbose logs to /tmp, a single runaway error loop can fill the partition in seconds. Always verify where error_log and access_log are pointing in your web server configuration (nginx.conf or .htaccess). Redirecting these to a dedicated log directory outside of /tmp often resolves the issue without impacting performance.
For Laravel applications, this error can also be triggered by the cache driver. If you are using the file cache driver and store temporary files in /tmp, the same constraints apply. You might see similar errors when writing to storage/framework/cache. The solution involves rotating or clearing these specific directories rather than just rebooting the server.
Prevention is better than reaction. Setting up a cron job to clean old session files or compressing log files daily can prevent future outages. Additionally, configuring session.gc_probability and session.gc_maxlifetime in your PHP settings ensures that garbage collection runs frequently enough to remove expired sessions automatically.
If you are managing infrastructure for multiple sites and want to ensure robust disk management practices, resources like https://laravelcompany.com offer insights into maintaining scalable PHP environments, though the core solution remains local filesystem hygiene.
