npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vercel-php80

v0.0.2

Published

Vercel PHP8 runtime

Downloads

4

Readme


😎 Getting Started

Let's picture you want to deploy your awesome microproject written in PHP and you don't know where. You have found Vercel it's awesome, but for static sites. Not anymore! I would like to introduce you your new best friend vercel-php, PHP runtime for Vercel platform.

Most simple example project is this one, using following project structure.

project
├── api
│   └── index.php
└── vercel.json

First file api/index.php is entrypoint of our application. It should be placed in api folder, it's very standard location for Vercel.

<?php
phpinfo();

Second file vercel.json is pure gold here. Setup your project with configuration like this and voila. That's all.

{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  }
}

Last thing you have to do is call vercel. If you are more interested take a look at features and usage.

# Install it globally
npm i -g vercel

# Log in
vercel login

# Let's fly
vercel

Are you ready to deploy your first PHP project to Vercel? Click & Go!

🤗 Features

  • Architecture: PHP development server (🚀 fast enough)
  • PHP version: 8.1.4
  • Extensions: apcu, bcmath, brotli, bz2, calendar, Core, ctype, curl, date, dom, ds, exif, fileinfo, filter, ftp, geoip, gettext, hash, iconv, igbinary, imap, intl, json, libxml, lua, mbstring, mongodb, msgpack, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, phalcon, Phar, protobuf, readline, redis, Reflection, runkit7, session, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, swoole, timecop, tokenizer, uuid, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache, zlib, zip
  • Speed: cold ~250ms / warm ~5ms
  • Memory: ~90mb
  • Frameworks: Nette, Symfony, Lumen, Slim, Phalcon

List of all installable extensions is on this page https://blog.remirepo.net/pages/PECL-extensions-RPM-status.

💯 Versions

⚙️ Usage

Before you can start using this runtime, you should learn about Vercel and how runtimes works. Take a look at blogpost about Serverless Functions.

You should define functions property in vercel.json and list PHP files directly or using wildcard (*). If you need to route everything to index, use routes property.

{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  },
  "routes": [
    { "src": "/(.*)",  "dest": "/api/index.php" }
  ]
}

Do you have more questions (❓)? Let's move to FAQ.

👨‍💻 vercel dev

For running vercel dev properly, you need to have PHP installed on your computer, learn more. But it's PHP and as you know PHP has built-in development server. It works out of box.

php -S localhost:8000 api/index.php

👀 Demo

  • official - https://php.vercel.app/
  • phpinfo - https://phpshow.vercel.app/
  • extensions - https://phpshow.vercel.app/ext/
  • ini - https://phpshow.vercel.app/ini/
  • JSON API - https://phpshow.vercel.app/api/users.php
  • test - https://phpshow.vercel.app/test.php

PHP

🎯Examples

Browse more examples. 👀

📜 Resources

🚧 Roadmap

See roadmap issue. Help wanted.

⁉️ FAQ

project
├── api
│   ├── index.php
│   ├── users.php
│   └── books.php
└── vercel.json
{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    },

    // Can be list also directly

    "api/index.php": {
      "runtime": "[email protected]"
    },
    "api/users.php": {
      "runtime": "[email protected]"
    },
    "api/books.php": {
      "runtime": "[email protected]"
    }
  }
}
{
  "functions": {
    "api/index.php": {
      "runtime": "[email protected]"
    }
  },
  "routes": [
    { "src": "/(.*)",  "dest": "/api/index.php" }
  ]
}

Additional function properties are memory, maxDuration. Learn more about functions.

{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]",
      "memory": 3008,
      "maxDuration": 60
    }
  }
}

Yes, Composer is fully supported.

project
├── api
│   └── index.php
├── composer.json
└── vercel.json
{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  }
}
{
  "require": {
    "php": "^8.1",
    "tracy/tracy": "^2.0"
  }
}

It's also good thing to create .vercelignore file and put /vendor folder to this file. It will not upload /vendor folder to Vercel platform.

Yes, you can override php configuration. Take a look at default configuration at first. Create a new file api/php.ini and place there your configuration. Don't worry, this particulary file will be removed during building phase on Vercel.

project
├── api
│   ├── index.php
│   └── php.ini
└── vercel.json
{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  }
}
# Disable some functions
disable_functions = "exec, system"

# Update memory limit
memory_limit=1024M

Runtimes support excluding some files or folders, take a look at doc.

{
  "functions": {
  "api/**/*.php": {
    "runtime": "[email protected]",
    "excludeFiles": "{foo/**,bar/config/*.yaml}",
  }
}

If you want to exclude files before uploading them to Vercel, use .vercelignore file.

Calling composer scripts during build phase on Vercel is supported via script named vercel. You can easilly call php, npm or node.

{
  "require": { ... },
  "require-dev": { ... },
  "scripts": {
    "vercel": [
      "@php -v",
      "npm -v"
    ]
  }
}

Files created during composer run vercel script can be used (require/include) in your PHP lambdas, but can't be accessed from browser (like assets). If you still want to access them, create fake assets.php lambda and require them. Example of PHP satis.

If you are looking for config.includeFiles in runtime, unfortunately you can't include extra files. All files in root folder are uploaded to Vercel, use .vercelignore to exclude them before upload.

I think the best way at this moment is use PHP Development Server.

php -S localhost:8000 api/index.php

👨🏻‍💻CHANGELOG

Show me CHANGELOG

🧙Contribution

  1. Clone this repository.
  2. Install NPM dependencies
    • make install
  3. Make your changes
  4. Run TypeScript compiler
    • make build
  5. Run tests
    • make test
  6. Create a PR

📝 License

Copyright © 2019 f3l1x. This project is MIT licensed.