Do you support sockets with PHP?
Ce contenu n’est pas encore disponible dans votre langue.
Yes. PHP socket functions are available on Ruachost hosting.
Sockets let your PHP scripts open network connections directly, for example to talk to another server or a service that doesn’t use plain HTTP. You can use:
- The sockets extension, with functions such as
socket_create(),socket_connect()andsocket_write(). - Stream functions such as
fsockopen()andstream_socket_client(), which are often simpler.
<?php$fp = fsockopen('example.com', 80, $errno, $errstr, 10);if (!$fp) { echo "Error: $errstr ($errno)";}Things to know
Section titled “Things to know”- Your scripts can make outgoing connections. If a connection to a particular port is blocked, contact support and tell us the host and port.
- Shared hosting is not suitable for long-running socket servers that listen for incoming connections all the time. For real-time features, see Do you support WebSocket connections?
- If you see “Call to undefined function socket_create()”, open Select PHP Version → Extensions in cPanel and tick sockets. See Changing PHP versions and settings using PHP Selector.
Cette page vous a-t-elle aidé ?
Merci pour votre retour.