VIP Go platform specific
This document is for sites running on VIP Go.
The VIP Platform has been designed with for high-scale performance and security. One of the ways we do that is to run all web servers in read-only mode. This helps protect applications on the platform against many common form of attack (e.g. vulnerabilities that allow installation of backdoor shells and other malicious files); allows for automated, high-capacity horizontal scaling; and dynamic image resizing and manipulation.
Media Uploads #
The VIP Platform stores all uploaded media in a globally distributed object store called the VIP Files Service. This is seamlessly integrated with your WordPress application and all common operation including uploads, cropping, editing, and deletes work as expected.
All images uploaded to the VIP Files Service can make use of the Photon API, which allows for dynamic resizing and other manipulation (cropping, letterboxing, filters, etc.). Because image sizes all are created on-the-fly, uploads are significantly faster and changes to image sizes is much easier (no need to run scripts to regenerate files).
Programmatic Access to Media Uploads #
For programmatic access to media stored in the VIP Files Service, such as uploading and modifying files, you can use several different APIs.
For more complex interactions, we’ve integrated a custom PHP Stream Wrapper, which allows most filesystem functions (e.g.
file_put_contents, etc.) to work with media uploads. This means that most plugins that interact with media uploads will work on the VIP Platform without any modifications. There are some caveats
A few caveats to be aware of:
- This only works for the uploads directory (i.e. paths that begin with
/wp-content/uploads/; other paths will not work).
- You must use the WordPress function
wp_upload_dir()to generate the correct, writeable path (hard-coding a path like
/wp-content/uploads/...will not work).
- Currently, not all filesystem functions and operations are supported (e.g. directory traversal)
- Not all use cases are ideal or supported (e.g. files with high volumes of updates, such as logging)
- Because communication with the VIP Files Service happens over HTTP, high number of function calls (e.g. lots of
file_existschecks) can result in a performance hit and should be used with caution.
Here’s a simple example of how to upload a file using PHP functions:
$csv_content = '1,hello,admin'; $upload_dir = wp_get_upload_dir()['basedir']; $file_path = $upload_dir . '/csv/updated.csv'; file_put_contents( $file_path, $csv_content ); // The file will now be accessible at <a href="https://example-com.go-vip.net/wp-content/uploads/csv/updated.csv">https://example-com.go-vip.net/wp-content/uploads/csv/updated.csv</a>
Here’s an example that parses an uploaded CSV and stores the contents in a variable:
$csv_attachment = get_attached_file( 1234 ); $csv_file = file( $csv_attachment ); $csv_content = array_map( 'str_getcsv', $csv_file );
Local File Operations #
There may be cases where you need to perform local manipulations to temporary files (e.g. download a zip, extract its contents, and then upload them to WordPress). For these cases, you can use the system temp directory, which is the only local, writeable path on web servers on the VIP Platform.
A few things to keep in mind:
- Use get_temp_dir() to find the right path. Or if you need to generate a temporary file, use
- You should clean up and remove all files after they’re no longer needed. Use unlink() to remove those files.
- Files and directories can only be relied on for the duration of the current request.
- Each request may be served by a different container and the sequence of requests from a given user are not guaranteed to be served by the same container.
- Containers are transient and may be created and destroyed due to autoscaling.
If you have any questions about the VIP Files Service or working with the filesystem on the VIP Platform, please don’t hesitate to get in touch with the VIP team so we can work with you on the implementation.