PHP多线程cURL替代方案提出,但是它好吗?

时间:2021-11-10 00:35:19

Because PHP doesn't have multithreading capabilities I am trying to find a workaround to speed up a simple process.

因为PHP没有多线程功能,所以我试图找到一种解决方法来加速一个简单的过程。

The process is I am posting data to a webpage with various permutations in the post-data on each request. In a foreach loop I am checking each request response to see if a string exists using strspos. When it is found, it breaks and returns the page. There are around 1000 requests, and it takes bout 1 minute to complete or longer.

这个过程是我将数据发布到每个请求的后期数据中具有各种排列的网页。在foreach循环中,我正在检查每个请求响应,以查看是否存在使用strspos的字符串。找到它后,它会中断并返回页面。大约有1000个请求,需要1分钟才能完成或更长时间。

As I don't want to use additional libraries, my idea was to exec standalone scripts passing each permutation of post data (say 1000 processes). Each process will only write to a file if the string is found. And on the main script I will run a loop checking if file exists, when it does find that the file exists, can read the file for the post data that was correct.

由于我不想使用额外的库,我的想法是执行独立脚本传递发布数据的每个排列(比如1000个进程)。如果找到字符串,每个进程将只写入文件。在主脚本上,我将运行一个循环检查文件是否存在,当它确实发现文件存在时,可以读取文件以查找正确的帖子数据。

It seems sound in theory, but I wanted to check if this is a ridiculous solution for a problem that has much simpler solutions!

理论上似乎听起来很合理,但我想检查这是否是一个有更简单解决方案的问题的荒谬解决方案!

Thanks.

1 个解决方案

#1


0  

One solution is using process control library

一种解决方案是使用过程控制库

http://php.net/manual/en/book.pcntl.php

I don't know if you have support for them installed

我不知道你是否支持安装它们

#1


0  

One solution is using process control library

一种解决方案是使用过程控制库

http://php.net/manual/en/book.pcntl.php

I don't know if you have support for them installed

我不知道你是否支持安装它们