|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66943 Can't open COM10 or higher serial ports
Submitted: 2014-03-22 22:19 UTC Modified: -
Avg. Score:3.2 ± 0.4
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: Assigned:
Status: Open Package: Streams related
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
New email:
PHP Version: OS:


 [2014-03-22 22:19 UTC]
PHP on Windows can't open (using fopen()) serial ports greater than COM9:, fe fopen("COM10:" or fopen("COM11:" fail.

This occurs regardless of the mode passed to fopen. "r+b" is the correct mode for serial on Windows. "r+" allows reading and writing. "b" sets it to binary mode, important because: Windows converts non-ASCII (>127) bytes if the stream is in text mode.

I am using Serial over USB (FTDI driver) to communicate with a microcontroller (Arduino).

In Serial over USB (not real serial) on Windows you can rename COM ports, so users can work around this problem by renaming COM ports to unused ports like COM7 or COM8, etc... for instructions, see my PR below for the PhpSerial class.

I have modified the PhpSerial class to work on Windows (for both read and write), see  as an example of how to use serial ports from PHP.

I suspect the cause is in the realpath() parser, checking for COM*: with a one integer but not two (not COM**: )

Test script:
// connect Serial-over-USB device to Windows PC, such as an Arduino Uno
//         (which uses an FTDI controller, get the FTDI driver for Windows
//          from Sourceforge or Arduino)
fopen("COM10:", "r+b");

Expected result:
fopen() returns a resource handle

Actual result:
"failed to open stream: invalid argument"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-23 22:33 UTC]
Instead of using the COMn: notation, using the \\.\COMn notation avoids this issue.

I have a PR for PhpSerial which uses this so it can open 2 digit Com ports (COM 11, COM12, etc...), see

Thanks to Dennis Ahrens for figuring this out.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jul 03 17:01:26 2020 UTC