whoami

Lucas Jenß

cat /etc/motd

The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.

Close-up of white dominoes with black dots standing on green felt surface, shallow depth of field, focused mood

ls -la ~/languages/

total 8
drwxr-xr-x
▶ PHP
▶ Ruby
▶ Scala
▶ C#
▶ JavaScript
▶ Objective-C
▶ Shell Scripting

ls -la ~/toolchain/

total 7
drwxr-xr-x
▶ Typo3
▶ Akka
▶ Capistrano
▶ Git
▶ MAMP
▶ Adobe Illustrator
▶ NSTrackingArea (Cocoa)

uname -a

platforms
drwxr-xr-x
▶ Mac OS X
▶ Unix

Using PHP stream wrappers to read remote files in TYPO3 extensions

TYPO3 extensions sometimes need a file that never passes through the CMS: a partner catalogue, licence feed, deployment manifest, or remote SVG asset. PHP stream wrappers provide a compact way to read many of those resources through familiar file functions, keeping extension code consistent between local development and production.

That tidiness can be deceptive. file_get_contents() may hide a DNS failure, an HTTP error, a slow response, or an unexpectedly large payload. A wrapper can also expose a server-side request forgery risk when users influence the URL. Treat remote access as an input boundary, not simply as shorthand for opening a link.

Australian deployments add practical wrinkles. A developer in Melbourne may test through a local proxy while production runs in a Sydney cloud region, and a colleague on regional broadband may see different timeout behaviour. Imports tied to Australian Eastern Standard Time can also cross local midnight when daylight saving changes.

The practical goal is not to replace every HTTP client with PHP streams. It is to create a small, testable layer for protocols, timeouts, validation, caching, and logging. TYPO3 should receive a local File or controlled value, regardless of where the source began.

How PHP exposes remote resources

A stream wrapper maps a URL scheme to an implementation. PHP commonly registers http, https, ftp, and file, while an extension can add a scheme such as partnerfeed with stream_wrapper_register(). Calling stream_get_wrappers() shows what the current PHP installation supports. URL wrappers also depend on allow_url_fopen, although a dedicated HTTP client may still work when that setting is disabled.

Mechanism Best fit Failure visibility Main limitation
file_get_contents() Small, trusted HTTPS documents Low unless status is inspected No practical response-size cap
fopen() with a context Controlled reads and temporary files Moderate with metadata checks Must enforce limits and close handles
PSR-18 HTTP client APIs and status-rich integrations Strong and easy to test Adds configuration and dependencies
Custom registered wrapper Legacy protocols or provider bridges Depends on implementation Can affect global PHP behaviour

Context options shape a request without changing its destination. An HTTPS context can define a timeout, User-Agent, protocol version, and redirect policy. A custom scheme can implement stream_open(), stream_read(), stream_stat(), and stream_close(), delegating to a TYPO3 service or another provider. It should not replace a built-in wrapper globally, because other extensions may rely on the standard behaviour.

Keeping remote access out of extension controllers

Give the extension one service, such as RemoteFileReader, and inject it where needed. Controllers should request a catalogue or asset through that interface instead of opening URLs inline. The implementation can then enforce the host allowlist, create stream contexts, cap the response, and translate failures into exceptions that TYPO3 can report consistently.

Keep endpoints in extension configuration, but keep credentials in the environment or a secret provider. Constructor injection makes the reader straightforward to replace in tests. Registering the implementation through the extension’s dependency-injection configuration also avoids static helper calls that are difficult to mock and audit.

That boundary is a delivery decision as well as a code choice. For the wider operational context, the Sofcase site is a useful place to frame ownership, support, and failure handling before an integration reaches production. A partner using a .com.au domain may also need different DNS, proxy, or support arrangements from a local test fixture.

Choosing a protocol and read strategy

Use https for network sources unless the provider offers a protocol with stronger operational controls. FTP remains useful in some older integrations, but unencrypted variants expose credentials and content. Third-party wrappers may add S3 or object-storage support, yet they also introduce another dependency whose registration, maintenance, and failure semantics must be understood.

For a small trusted document, file_get_contents() is readable, although it offers little control over memory use. fopen() with a stream context is usually the better TYPO3 default: set the timeout, read at most the permitted bytes plus one, and close the handle in a finally block. Stream the response into a temporary file when the payload may be large.

Wrappers are strongest for file-like retrieval. APIs needing signed requests, complex redirects, JSON error bodies, or precise status handling may be better served by a PSR-18 client. The two approaches can coexist: the client can fetch the resource, while the extension stores it through the same local-file boundary. Schedule cross-state jobs in UTC because Perth runs two or three hours behind Sydney depending on daylight saving.

Handling failures and validating payloads

Do not treat a returned false as “the file is missing”. Capture the warning or exception, classify DNS, connection, TLS, timeout, and HTTP failures, and include the safe host name and attempt time in the log. Where the HTTP wrapper is used, inspect response status and headers rather than assuming a successful body. Direct wording such as “partner feed timed out” is more useful in an Australian support handover than a generic transport error.

Validate size, media type, checksum, and expected structure before the payload reaches a parser. Content-Length can be misleading, so enforce the byte limit while reading. Remote SVG deserves special care: reject active content and unexpected external references. An SVG filter workflow shows how Illustrator previews and browser rendering can diverge, which is useful when diagnosing why a fetched asset differs from its source.

Cache successful downloads through TYPO3’s file system abstraction rather than hitting the partner for every page request. Store the body atomically, use a temporary file plus rename, and include the source URL’s hash, checksum, and expiry in cache metadata. A lock prevents concurrent imports writing the same target, while a stale fallback can keep the site usable during a short outage.

Securing hosts, redirects, and secrets

Allowlist exact schemes, hosts, ports, and path prefixes. A host check alone is not enough: resolve it and reject loopback, link-local, private, and reserved addresses, then validate every redirect destination. Disable automatic redirects for the wrapper and follow only reviewed locations, or use an HTTP client that exposes the same checks. This blocks common server-side request forgery paths through redirects or internal services.

Keep TLS verification enabled, including peer and host-name checks. A disabled certificate check may hide an interception problem rather than fix it. Supply authentication through request headers or provider-specific mechanisms, not permanent query parameters, because URLs often leak through access logs, browser history, exception reports, and shared debugging screenshots.

Treat remote payloads as untrusted data and store secrets outside version control. Rotate provider tokens, restrict them to the required scope, and avoid placing them in configuration values that TYPO3 caches or exports. If personal information is involved, check the Australian Privacy Act, organisational policy, and client contracts. Australian data-residency expectations can influence endpoint selection, but they do not remove the need for minimisation and access controls.

Testing and deploying the extension

Test the reader through an injected interface, then add integration tests against a controlled local HTTPS fixture. Cover successful downloads, authentication failures, redirects, slow responses, oversized bodies, invalid media types, and checksum mismatches. A custom wrapper needs its own test double; otherwise unit tests may accidentally depend on the public internet.

Check allow_url_fopen, registered wrappers, outbound proxies, DNS behaviour, and trusted certificate bundles on every deployment target. Managed Australian cloud hosts can have egress rules that a laptop does not. Warm or flush the relevant TYPO3 caches after configuration changes. The separation between process definition and release orchestration in Capistrano systemd units is a useful parallel for making deployment responsibilities explicit.

Log the UTC timestamp, source host, status, duration, byte count, and cache result, but never the secret token or full sensitive URL. Alert on repeated timeout or TLS failures. Test from the production region and, where practical, from a regional Australian connection, because a fast Sydney response does not guarantee a reliable import from everywhere.

A reliable release checklist

Before enabling a new remote source, make its operating rules visible to support and deployment staff. The extension should have a narrow contract, rather than becoming a general-purpose downloader.

  • Confirm that the required wrapper is registered on every supported PHP and TYPO3 environment.
  • Allowlist hosts and validate redirect destinations against private and reserved networks.
  • Set explicit timeouts and a byte limit for every remote request.
  • Verify HTTP status, media type, payload size, and checksum before use.
  • Cache valid downloads atomically and document the expiry and stale-data behaviour.
  • Load credentials from secrets, redact them from logs, and test token rotation.

Start with one allowlisted HTTPS source in a non-production branch. Exercise its timeout, cache, and failure paths, publish the ownership details, and only then widen the protocol list. That gives the extension a dependable boundary rather than a collection of remote-file surprises.


cat ~/interests.json

KeyValue
editorTerminal-first workflow
osMac OS X / Unix
vcsGit, distributed version control
deployCapistrano, cron automation
graphicsSVG, Adobe Illustrator troubleshooting
networkingIP validation, SSH, VPN

git log --oneline --reverse

2013-10-30

Solving SVG import issues in Adobe Illustrator CS6 and CC

When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.

2013

Solving NDK build issues on OS X

Troubleshooting native development kit compilation problems on Mac OS X.

2013

Programmatically adding PHP generated TypoScript to the backend configuration

Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.

2013

ArgumentError: Could not parse PKey: no start line

Debugging an SSH key parsing error encountered during deployment.

2011-08-04

Validating IP-Addresses in PHP

Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.

2011-07-09

Cocoa: Using NSTrackingArea

A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.


cat ~/contact.txt

github: github.com/x3ro
stackoverflow: x3ro
coderwall: coderwall.com/x3ro
twitter: @x3rames