Mirroring the PHP Manual on Local Linux PC

4330
Share:
mirroring-the-php-manual-on-local-linux-pc

Background

I call myself a programmer, but I have issue when it comes to memorizing function parameters. For example, in PHP there's a function called explode, to split a string by string. Most of the times, I always need to ask Google about the parameter's sequence. I know the logic that it should receive delimiter and the string which needs to be splitted, I just need to check wheter it's delimiter or string for the first parameter.

That method should working fine, when internet connectivity is not a problem. But when the internet is down or I'm out of network coverage, I have to find another method. On Windows there's a PHP Manual in a CHM format: complete and searchable. As now I'm using Linux, what options do I have?

Options

On their webpage, it shows four formats available to be downloaded.

  1. Single HTML file
    I don't have any idea why this is available as an option. When uncompressed, it's a ~60 MB HTML file. Try to open the file without crashing web browser.
  2. Many HTML files
    Tried this option but it lacks search function.
  3. HTML Help file
    This could work on Linux after installing xCHM. I just don't like how it looks like, so I don't use this option.
  4. HTML Help file (with user notes)
    Same as above

So I'm thinking of another method: mirroring their website. Luckily, this method is possible and officially supported. Check http://www.php.net/mirroring.php to read more.

Solution

I have made up my mind to use alternative method: mirroring. Here's how I get the PHP Manual working on my PC:

  1. Make sure rsync installed: which rsync
  2. Choose Regional Rsync Nodes which cover my area. In my case it's ASIA.RSYNC.PHP.NET
  3. Choose where the PHP manual's web root directory. In my case it's ~/html/phpman
  4. Type this command on console:
    rsync -avzC --timeout=600 --delete --delete-after --exclude='distributions/**' ASIA.RSYNC.PHP.NET::phpweb ~/html/phpman --include='manual/en/' --include='manual/en/**' --exclude='manual/**' --exclude='distributions/manual/**' --exclude='extra/**' --exclude='archive/**' --exclude='releases/**'
  5. Wait for the rsync finished.
  6. Configure web server's virtual host. I'm using nginx, here's what my configuration:
    server {
            listen 80;
            root /var/www/html/phpman;
            index index.php index.html index.htm index.nginx-debian.html;
            server_name phpman.local;

            location / {
                    try_files $uri $uri/ =404;
            }

            location ~ \.php$ {
                    include snippets/fastcgi-php.conf;
                    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            }
    }
  7. Add virtual host to /etc/hosts
    127.0.0.1       phpman.local
  8. Reload web server: sudo service nginx reload
  9. Done.

After playing along, I found one bug: The search itself is working fine, but when clicking the search result, it won't open a page. My quick observation is it's caused by the URL is not having a .php suffix, so the file cannot be found.

After 10 minutes doing my magic, the search function is working flawlessly.

Mirroring PHP Manual

Mirroring PHP ManualHere's my magic's secret: file /js/search.js line 312-315

            // If the user has selected an autocomplete item and hits enter, we should take them straight to the page.
            searchTypeahead.on("typeahead:selected", function (_, item) {
                window.location = "/manual/" + options.language + "/" + item.id + ".php"; // Notice the .php suffix.
            });
Tags
Share:

2 comments

  1. Its such as you learn my mind! You appear to know
    a lot approximately this, like you wrote the ebook in it or something.

    I think that you can do with a few p.c. to power the
    message house a little bit, however instead of that,
    that is excellent blog. A great read. I'll certainly be back.

Leave a reply

Your email address will not be published. Required fields are marked *