<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vova Durcoin</title>
    <description>The latest articles on DEV Community by Vova Durcoin (@durcoin).</description>
    <link>https://dev.to/durcoin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3904223%2Feac1ea94-91da-43e1-9f58-70888d7c10d5.jpg</url>
      <title>DEV Community: Vova Durcoin</title>
      <link>https://dev.to/durcoin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/durcoin"/>
    <language>en</language>
    <item>
      <title>I built a media host in one PHP file. Here's what 900 lines can do.</title>
      <dc:creator>Vova Durcoin</dc:creator>
      <pubDate>Wed, 29 Apr 2026 11:29:24 +0000</pubDate>
      <link>https://dev.to/durcoin/i-built-a-media-host-in-one-php-file-heres-what-900-lines-can-do-1dl7</link>
      <guid>https://dev.to/durcoin/i-built-a-media-host-in-one-php-file-heres-what-900-lines-can-do-1dl7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;TL;DR: One &lt;code&gt;index.php&lt;/code&gt; file. Zero dependencies. Zero database. &lt;br&gt;
Scales to 500k files. MIT licensed. &lt;a href="https://dev.toyour-link"&gt;Code on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The itch I was scratching
&lt;/h2&gt;

&lt;p&gt;I have a folder of MP3s I wanted to share with a small audience. &lt;br&gt;
Standard options were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Plex / Jellyfin&lt;/strong&gt; → hours of Docker and configuration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;S3 + CloudFront&lt;/strong&gt; → 40 AWS IAM tabs later I give up
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SoundCloud / YouTube&lt;/strong&gt; → not self-hosted, algorithmic control&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WordPress + plugin&lt;/strong&gt; → bloat, database, security patches forever&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I just wanted: "upload files, visitors see them, done." So I wondered &lt;br&gt;
— how minimal can a media server actually be?&lt;/p&gt;
&lt;h2&gt;
  
  
  The constraints I gave myself
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Single &lt;code&gt;.php&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;No database&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;composer.json&lt;/code&gt; or any package manager&lt;/li&gt;
&lt;li&gt;No build step (no webpack, no TypeScript compilation)&lt;/li&gt;
&lt;li&gt;Must handle 500k+ files without choking&lt;/li&gt;
&lt;li&gt;Must work on $3/month shared hosting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Six weeks later: &lt;strong&gt;900 lines of PHP&lt;/strong&gt;, and it actually does all of that.&lt;/p&gt;
&lt;h2&gt;
  
  
  Architecture: JSON index cache
&lt;/h2&gt;

&lt;p&gt;The trick to scale a single-file script is avoiding filesystem scans &lt;br&gt;
on every request. On first load:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;rebuildIndex&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="nv"&gt;$dh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;opendir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;readdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$dh&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;is_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$files&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'n'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'s'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;filesize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'c'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;categorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;pathinfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PATHINFO_EXTENSION&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$files&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;file_put_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'_index.cache.json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$files&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$files&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Subsequent requests read &lt;code&gt;_index.cache.json&lt;/code&gt; instead. Cache TTL is &lt;br&gt;
1 hour. Tested with 500k dummy files — response times stay under 50ms.&lt;/p&gt;
&lt;h2&gt;
  
  
  The hardest part: Ed25519 verification in PHP
&lt;/h2&gt;

&lt;p&gt;I wanted users to authenticate via Waves blockchain wallet &lt;br&gt;
(Keeper extension). Waves uses &lt;strong&gt;Curve25519&lt;/strong&gt; public keys but &lt;br&gt;
signs with &lt;strong&gt;Ed25519&lt;/strong&gt;. You can't verify Ed25519 signatures with &lt;br&gt;
a Curve25519 key directly.&lt;/p&gt;

&lt;p&gt;The birational map between the two curves:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y = (u - 1) / (u + 1) mod p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;u&lt;/code&gt; is the Montgomery x-coordinate (Curve25519) and &lt;code&gt;y&lt;/code&gt; is &lt;br&gt;
the Edwards y-coordinate (Ed25519). Plus reconstructing the sign bit &lt;br&gt;
from byte 63 of the signature.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;curve25519ToEd25519&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$curvePk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$signBit&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gmp_init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2^255 - 19'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$u&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gmp_mod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;gmp_init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;bin2hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;strrev&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$curvePk&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$uPlus1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gmp_mod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;gmp_add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$inv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gmp_invert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$uPlus1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gmp_mod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;gmp_mul&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;gmp_sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;$inv&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;$p&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// ... encode back to 32 bytes, set sign bit&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then feed to &lt;code&gt;sodium_crypto_sign_verify_detached()&lt;/code&gt;. Works reliably &lt;br&gt;
once you get the byte-order and sign-bit handling right.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other things I crammed into 900 lines
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTP byte-range streaming&lt;/strong&gt; for audio/video (&lt;code&gt;Accept-Ranges: bytes&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MediaSession API&lt;/strong&gt; so mobile lock-screen controls work&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Infinite scroll&lt;/strong&gt; via IntersectionObserver with cancelable fetches&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;10 language translations&lt;/strong&gt; including RTL (Arabic)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dark + grayscale light themes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mobile-first responsive&lt;/strong&gt; (row layout on phones, grid on desktop)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shareable URLs&lt;/strong&gt; that auto-start playlists: 
&lt;code&gt;#play=audio&amp;amp;list=a.mp3|b.mp3&amp;amp;from=a.mp3&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Start with constraints, not features.&lt;/strong&gt; The "one file" rule &lt;br&gt;
forced every decision to justify itself in bytes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP-range streaming is underrated.&lt;/strong&gt; MediaSession + byte-range &lt;br&gt;
on a static file gives you 90% of what "proper" streaming services do.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JSON cache &amp;gt; database for read-heavy workloads.&lt;/strong&gt; For this use &lt;br&gt;
case, filesystem metadata in JSON is faster than any SQL query &lt;br&gt;
because there's no query — just &lt;code&gt;json_decode()&lt;/code&gt; once.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What this is NOT
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Not a Plex replacement. It doesn't transcode, scrape metadata, 
manage libraries.&lt;/li&gt;
&lt;li&gt;Not for shared multi-user servers. One deployment = one creator.&lt;/li&gt;
&lt;li&gt;Not secure by itself — put it behind Cloudflare or nginx with 
rate limiting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code:&lt;/strong&gt; &lt;a href="https://dev.tolink"&gt;https://github.com/vekuz/durcoin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Demo:&lt;/strong&gt; &lt;a href="https://dev.tolink"&gt;https://djdurcoin.ru/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MIT licensed. Fork it, break it, rewrite it. If you find a cleaner &lt;br&gt;
way to do the Ed25519 dance in PHP — please tell me.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Building minimalist tools is a discipline. Every feature has to &lt;br&gt;
justify its bytes. Turns out: most web apps can be 10× smaller than &lt;br&gt;
they are. Maybe yours too.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>selfhosted</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
