简体   繁体   English

一种使用PHP检查端口的方法(多线程?)

[英]A way to check ports with PHP (Multithreading?)

I'm currently using cURL multi to check thousands of http status codes in a few seconds and it works very well. 我目前正在使用cURL multi在几秒钟内检查数千个http状态代码,并且效果很好。
However, I'm wondering - is their anyway I can check if a port is responding (eg mysql) using cURL or another PHP multitasking method? 但是,我想知道-是否可以使用cURL或其他PHP多任务方法检查端口是否正在响应(例如mysql)?

You can use fsockopen() to scan ports, but each PHP script runs on 1 thread. 您可以使用fsockopen()扫描端口,但是每个PHP脚本都在1个线程上运行。

http://php.net/manual/en/function.fsockopen.php http://php.net/manual/en/function.fsockopen.php

The short answer : 简短的答案:

The are no threads in PHP. 在PHP中没有线程。

However, you may take a look to the pcntl extension. 但是,您可以查看pcntl扩展名。 It is not about threads, it is fork (that means that a process will be created for each fork). 这与线程无关,而是分叉(这意味着将为每个分叉创建一个进程)。

A Thread extension has been developed some years ago but it has not been updated for 2 years now. 几年前已经开发了Thread扩展,但现在已经2年没有更新了。

Forks are totally valuable and may be used in your use case however it is not easy to maintain or write. 叉子是完全有价值的,可以在您的用例中使用,但是它很难维护或编写。 Depending on you needs you may better want to work with python or perl which both have better thread support. 根据您的需要,您最好使用python或perl,它们都具有更好的线程支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM