Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am in the process of connecting a Node.JS server with a PHP application (on the same VPS) and a solution that I have found was to communicate via cURL.

I am thinking of going one step further and instead of have an HTTP server running on a custom port, I will write a Node.js socket server that accepts a custom protocol, and my PHP would connect via raw sockets.

The reason is because I assumed that this is how PHP connects to a MySQL server (obviously via some sort of MySQL protocol).. am I right? Because I can connect to MySQL from a remote PHP application without any problems, so there must be some sort of network communication between the two!?

So my question is, can someone tell me how PHP connects to MySQL? There must be networking somewhere along the line.

EDIT: I know the MySQL runs on port 3306; this has got to be relevant to the PHP MySQL APIs..

share|improve this question
add comment

closed as off topic by John Conde, hjpotter92, Nifle, Danack, 0x499602D2 May 26 '13 at 13:17

Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

no it connects with high performance connectors not sockets directly http://dev.mysql.com/downloads/connector/

in fact the question is more of how does a particular data consumer connect to mysql, such as PHP (

mysql_
mysqli_
pdo

), python, ruby, etc. the above answer is the same

share|improve this answer
    
I've probably mis-termed my question, my question actually WAS how does PHP connect to MySQL server? Have edited question in accordance with terminology mistakes –  user965369 May 25 '13 at 23:34
    
follow my link, dont have php be a socket client or server. you can have node call http requests to php and have it execute mysqli_ or pdo, or you can have node.js talk directly to mysql with something like node-mysql –  Drew Pierce May 25 '13 at 23:39
    
No i was just comparing my methods of connecting PHP and Node with how I assumed the method PHP uses to connect with MySQL. Ie with sockets.. ? So does PHP connect to MySQL with sockets?! Or am I a fool –  user965369 May 25 '13 at 23:41
    
of course it ultimately does at a lower level but that is not something you will be doing with accept and bind on 3306. you would be using a higher level wrapper like what php does –  Drew Pierce May 25 '13 at 23:42
add comment

Apache doesn't speak to MySQL, node.js/PHP does the work. Apache just runs the script you requested.

share|improve this answer
    
Ok but how PHP connect to the MySQL server? –  user965369 May 25 '13 at 23:33
    
There are two ways. Either through a socket, which doesn't go through the network, or it uses localhost, and connects through that (port 3306 by default). PHP uses a library/extension which gives all the methods necessary to connect. php_mysql.so –  Farkie May 25 '13 at 23:39
add comment

PHP and other languages will use a mysql client library. This library in turn will implement the MySQL protocol detailed in the manual

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.