Image of an AS2 file transfer flow. Encrypting, Sending, Receiving, Decrypting.

Building a PHP AS2 Server with an AI coworker

Well, the other day (a few months ago), I decided that I wanted to see if I could build a PHP AS2 server that’s RFC 4130-compliant. So I did what any developer does these days: gave the RFC to Claude Code and asked it to build a framework agnostic set of classes in PHP that implement the protocol described in the RFC, with which one can create an AS2 server. Why not? https://github.com/leoman79x/php-as2

What is AS2, you ask? AS2 is a secure EDI transport protocol used for business-to-business document exchange. Security is achieved by using digital certificates and encryption. (Wikipedia)

I am a platform and integration developer in the EDI field, so I spend quite a bit of time configuring AS2 partnerships. Pretty boring… unless you’re me. =) For some reason, I enjoy reading RFCs and digging into the workings of communication protocols. AS2, FTP, SMTP, HTTP, TCP/IP, IRC… (I coded an IRC server in the ’90s and I’m currently working on a fun new IRC project. Maybe I’ll post about that later…) I’m also a web developer and I mostly develop with PHP these days.

In EDI-land, most things are pretty Windows-centric and it’s common for things to be coded in Java and C#, so it makes total sense to be coding platforms in PHP, I guess…

Why Build an AS2 Server in PHP?

I guess I started on this project back in November of 2025. As of this writing, it has a reference implementation for a receiver endpoint. This isn’t the first AS2 implementation in PHP out there. You’ll find several, if you poke around the interwebs a bit. Now, a server is usually a long-lived process, and the request/response web model isn’t quite the same environment. So, why would anyone want to do it in PHP? Who knows. I thought it would be fun, though.

Claude Code and Spec Kit

To build this project, I used Claude Code running the Opus model that was available then. I also had found a “Spec-driven Development” framework called Spec Kit that I wanted to try out. Spec-driven development works best when your spec is specific, which usually means a big long document with everything that could possibly be in the feature. I don’t have time for all that, so I gave a description of what I wanted to Claude and asked it to flesh out a bigger prompt for spec kit. Spec kit took that prompt from Claude and used it to make its own directory structure that included a plan file, a spec file, and a tasks file.

I’m sure I wasn’t using the project correctly, but after spec kit was done doing its thing, I had some semi-functioning code. I couldn’t quite get the model to one-shot the whole thing, so follow-up prompting was required, of course. After chatting back and forth for a bit, a workable system started to emerge.

What’s next?

So now that it exists, the next step for me is to read the code. lol. Aside from wanting to have an AS2 system to integrate into my PHP projects and not have a multi-language project, this is a bit of an educational and fun project. It also gave me a bit of practice in AI model wrangling. I don’t think it gave me too much trouble with this one. The double-prompting technique produced specific spec files, even if they were a bit overdone, which got me 85% of the way there. Not bad for a predictive-text code generator. hehe.

So, the project isn’t quite ready for anything near a production server, but have a look at the project and let me know what you think. My ultimate goal for this is to get it to a point where I can use it as a package in Laravel to make a full server application and admin UI. https://github.com/leoman79x/php-as2

Here are the links that appear above:
https://github.com/leoman79x/php-as2
https://en.wikipedia.org/wiki/AS2
https://www.rfc-editor.org/rfc/rfc4130
https://github.com/github/spec-kit

Let Neutron Development be your outsourced EDI team! Contact Us Here!

You may also like...

Popular Posts