Operations 3 min read

Boost Linux Performance with tmpfs: Fast Cache & PHP Optimization

This article explains how Linux's built‑in tmpfs (mounted at /dev/shm) can be leveraged for high‑speed caching and PHP session storage, detailing its advantages, setup steps, and practical examples with Squid and PHP to improve system performance.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Linux Performance with tmpfs: Fast Cache & PHP Optimization

By default Linux mounts /dev/shm as a tmpfs filesystem, which can use RAM and swap, unlike a traditional ramdisk that requires a block device and mkfs. tmpfs is a file system that can be mounted directly.

Advantages of tmpfs:

Dynamic size.

Lightning‑fast read/write because it resides in RAM.

Data disappears after reboot, so scripts may be needed for setup.

Practical usage example:

mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp

1. Use tmpfs for Squid cache directory:

vi /etc/squid/squid.conf
# change cache_dir line to:
cache_dir ufs /tmp 256 16 256

The first 256 means 256 MiB of memory for the cache.

2. Optimize PHP performance by storing session and temporary files on tmpfs. Since /dev/shm/tmp is bound to /tmp, adjusting php.ini to point session.save_path to /tmp (or leaving defaults) stores these files in RAM, improving speed.

After restarting services, Squid cache and PHP temporary files reside in tmpfs, providing faster access.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceLinuxPHPtmpfsSquid
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.