Can APIs be provided only through http? Can APIs be provided only through http?
Reply content:
Can APIs be provided only through http?
PHP does not have to be called as http. The interfaces of PHP and other applications are called SAPI. Different sapis decide how to call PHP. For example, Apache mod_php is an SAPI implementation for interaction between Apache and PHP. Similarly, the SAPI Implementation of CGI and FastCGI (such as fpm) is also used to call the PHP interpreter through HTTP.
In addition, there are many sapis, such as CLI sapis that support running PHP scripts through command lines. The pcntl_fork function of php can be used in a similar way as that of C (two forks) create a deamon process so that the PHP script can be used as a service.
Php supports socket for service interaction with other processes.
I wrote a small Demo to show you how to use PHP to write a Server. You can take a look:
PHP can do service, there is a PHP extension is used to develop high performance and high concurrency of TCP/UDP Server. Here: http://www4swoole.sinaapp.com/
The answer upstairs is awesome!