|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66943 Can't open COM10 or higher serial ports
Submitted: 2014-03-22 22:19 UTC Modified: 2020-09-07 12:52 UTC
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.
 [2020-09-07 12:52 UTC]
-Type: Bug +Type: Documentation Problem
 [2020-09-07 12:52 UTC]
This is a documented limitation of CreateFile[1]:

| To specify a COM port number greater than 9, use the following
| syntax: "\.\COM10".

Thus changing to doc problem.

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Mar 02 15:01:28 2024 UTC