curl_multi | PHP多线程数据采集 | Command Line Interface library

 by   woondroo PHP Version: Current License: No License

kandi X-RAY | curl_multi Summary

kandi X-RAY | curl_multi Summary

curl_multi is a PHP library typically used in Utilities, Command Line Interface applications. curl_multi has no bugs, it has no vulnerabilities and it has low support. You can download it from GitHub.

curl_multi
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              curl_multi has a low active ecosystem.
              It has 17 star(s) with 14 fork(s). There are 7 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              curl_multi has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of curl_multi is current.

            kandi-Quality Quality

              curl_multi has 0 bugs and 0 code smells.

            kandi-Security Security

              curl_multi has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              curl_multi code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              curl_multi does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              curl_multi releases are not available. You will need to build from source code and install.
              curl_multi saves you 73 person hours of effort in developing the same functionality from scratch.
              It has 189 lines of code, 10 functions and 2 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of curl_multi
            Get all kandi verified functions for this library.

            curl_multi Key Features

            No Key Features are available at this moment for curl_multi.

            curl_multi Examples and Code Snippets

            No Code Snippets are available at this moment for curl_multi.

            Community Discussions

            QUESTION

            Count how many curl_multi requests have been made
            Asked 2020-May-21 at 10:51

            I want to know when each curl request has been made when using curl_multi.

            My code so far:

            ...

            ANSWER

            Answered 2020-May-21 at 10:51

            My tests of hit has been strangly inconsistent

            yeah, no wonder. there's a bug in your code if several handles finish in the same exec() call, you will only read the message from the first of them, and the messages from the rest of the handles will be lost! (edit: but it's not your fault, the bug comes from your copypasta at https://www.php.net/manual/en/function.curl-multi-info-read.php , someone should fix the docs!) (edit2: fixed the docs: https://github.com/php/doc-en/pull/102 ) lets say that before

            Source https://stackoverflow.com/questions/61920359

            QUESTION

            How to turn Curl response into Json so I can use it on the front-end?
            Asked 2019-May-21 at 18:15

            I have a function which uses curl_multi to make several GET requests. However, I can't figure out how to turn the response to JSON so I could access it on the front end. Usually I use json_decode(), however, it is not working this time. Maybe it's because I'm trying to decode a whole array of strings instead of a singular string?. Currently the response looks like this on the front-end:

            And here's my function:

            ...

            ANSWER

            Answered 2019-May-21 at 18:15

            If you are expecting a json string from the curl_multi_getcontent($c) then you should decode it:

            Source https://stackoverflow.com/questions/56244002

            QUESTION

            "Could not resolve host" error with curl_multi on cURL version 7.64
            Asked 2019-Mar-07 at 22:35

            I'm getting "Could not resolve host" when I call curl_error($ch) in curl_multi context, the errno is 0 though, and the request is done successfully also(I'm getting the expected response from the remote server).

            I'm getting this error for all the requests in the curl_multi group, except for only the first request of them which is done without any error messages!

            (for example if the curl_multi has 10 sub requests attached to it, only the first request will not have the error and the other 9 will have the error)

            The code to reproduce the problem ...

            ANSWER

            Answered 2019-Mar-07 at 22:35

            I have the exact same issue: https://github.com/amazeeio/lagoon/issues/923

            This is a curl regression: https://github.com/curl/curl/issues/3629 - which has been solved since opening the bug.

            Thanks for the awesome test scripts :)

            Source https://stackoverflow.com/questions/54771917

            QUESTION

            Using libcurl multi interface for consecutive requests for same "easy" handle
            Asked 2019-Feb-02 at 02:47

            My development organization has its own wrapper implementation for threads and select(). The application needs to be enhanced to perform HTTPS requests, and I've decided to use libcurl. After some research, I see that the curl_easy_perform is a blocking call, so I've decided to use the curl_multi_perform approach for non-blocking calls to allow other work in the threads.

            The HTTPS request will need to be performed periodically to the same URL. I know I can keep the same curl_easy handle and give that to the curl_multi handle. I would perform the curl_multi_perform to get the results, but I would later need to use curl_multi_perform to resend the request, say in 5 minutes. So, this would be a consecutive request using the same easy handle. However, I'm not sure how the curl_easy interface tells the multi interface as to when to resend the request after I have received results from the first request. How do I accomplish this?

            (Maybe drop the easy handle from the multi handle, and re-add it to the multi handle when a request is needed again?)

            I presume that whatever technique is used, that the outgoing request will be using the same outgoing port.

            ...

            ANSWER

            Answered 2019-Feb-02 at 02:47

            (Maybe drop the easy handle from the multi handle, and re-add it to the multi handle when a request is needed again?)

            Correct. From the libcurl documentation:

            When a single transfer is completed, the easy handle is still left added to the multi stack. You need to first remove the easy handle with curl_multi_remove_handle and then close it with curl_easy_cleanup, or possibly set new options to it and add it again with curl_multi_add_handle to start another transfer.

            .

            I presume that whatever technique is used, that the outgoing request will be using the same outgoing port

            This is not guaranteed. libcurl will attempt to re-use existing connections that are associated with the easy handle, but if the previous connection has already died then a new connection with an unpredictable local port will be established.

            Source https://stackoverflow.com/questions/54483937

            QUESTION

            Speedup php api calls
            Asked 2018-Oct-26 at 09:14

            Hi everyone. So I need to check huge amount of rows in database via API calls. I managed to do that but it is very slow.

            Here are steps my code is doing:

            1.) I select unique identifiers from my local database.

            2.) I check them on remote database via curl_multi (100 at the time).

            3.) Depending on status code I update rows in my database.

            4.) Repeat first 3 steps until all rows are checked.

            How can I speedup this process ? At this time checking 600 rows takes more than one minute.

            ...

            ANSWER

            Answered 2018-Oct-24 at 09:45

            Have you tried to run the HTTP API calls by a new thread.

            Try this PHP project: https://github.com/petewarden/ParallelCurl

            According to the docs you need to:

            • Make a Parallel cURL object with the max. HTTP connections at the same time
            • Write a handler when the answer from the API arrives
            • Write the cURL calls when iterating the rows from the DB

            If it doesn't help, try to measure what takes the most time (DB fetching, API calls, DB update)

            Source https://stackoverflow.com/questions/52962805

            QUESTION

            php ideas to speed up script for 18000+ calls
            Asked 2018-Aug-06 at 17:29

            I have a script that make a few calls. The 1st call get a array of keys and hash code. Then goes into a foreach and calls out to a 2nd api that will return a list of items that is then pass into a 2nd foreach loop that work with that data and post to a mysql data base. it take 11 hours to run the script i need ideas on how i can speed this up have look in to multi processing but everything i see says it a dad idea to make web request. Any ideas or links are welcome. Here is the code

            ...

            ANSWER

            Answered 2018-Aug-05 at 20:38
            • Do not use SELECT * because through this you avoid using possible indices that might exist.
            • Use Indices (return to point 1)
            • Use IN (...) if possible and maybe break up your logic?
            • Use transactions for the updates / inserts? Do you have lock issues on your tables? If so, this would help to break up the flow of the process and you would have more control over what you try to establish; which is difficult to say with the information at hand.

            Source https://stackoverflow.com/questions/51697933

            QUESTION

            Use cURL Multi, but still not asynchronous
            Asked 2018-Aug-03 at 09:09

            I use curl_multi to scrap several site, and I hope it will run asynchronously or parallel so it will not other to finish first.

            I use jquery to trigger xmlhttprequest to php.

            But what I get it still run synchronous, I dont know what is wrong whether my code or my PC specification (I run local server use core-i5 and 4GB memory)

            This is my jquery code

            ...

            ANSWER

            Answered 2018-Aug-03 at 09:09

            You have it set up right kinda, but your logic is wrong. It looks like your only ever sending information to your php scripts for one url at a time. You might as well just use a regular curl request.

            Curl_multi is designed to fetch the data for multiple urls asynchronously. So that being said, you will want to feed the functions multiple urls.

            So here is an example of how to set up a good curl_multi routine. You will have to adapt this to your own code, but it's a good road map. Hope it helps.

            Source https://stackoverflow.com/questions/51668191

            QUESTION

            Why can't I define a "variable variable" as static in PHP?
            Asked 2018-Jan-19 at 15:46

            ANSWER

            Answered 2018-Jan-19 at 15:46

            There is a Note in the documentation page of static variables that says:

            Static declarations are resolved in compile-time.

            On the other hand, variable variables means the name of such a variable is stored in another variable and it might not be available at the compile time.

            In your example, the name of the variable you want to declare as static is computed on the runtime using the value of the $ip function argument.

            The problem you are trying to solve has a different solution. For example, you can store the open handlers in a static array:

            Source https://stackoverflow.com/questions/48344449

            QUESTION

            Multi threaded curl handling multiple connections at the same time
            Asked 2017-Dec-02 at 21:53

            Is curl_multi interface spawning new threads internally to handle multiple requests concurrently? Is it equal to spawning threads manually and just using curl_easy handles? What is more performant. I need to make up to 1000 concurrent requests.

            https://curl.haxx.se/libcurl/c/multithread.html

            Is using curl_multi equal to the example in the link above?

            From: https://curl.haxx.se/libcurl/c/libcurl-multi.html

            Enable multiple simultaneous transfers in the same thread without making it complicated for the application.

            What does it mean? How does it handle multiple transfers in the same thread? I could as well create 100 threads with 100 curl_easy handles and make requests there.

            Maybe the question should be: When to use multiple threads and when to use curl_multi.

            ...

            ANSWER

            Answered 2017-Dec-02 at 21:53

            There's no easy or simple answer. libcurl allows you and your application to make the decision and supports working in either mode.

            The libcurl multi interface is a single-core single-thread way to do a large amount of parallel transfers in the same thread. It allows for easy reuse of caches, connections and more. That has its clear advantages but will make it CPU-bound in that single CPU.

            Doing multi-threaded transfers will make each thread/handle has its own cache and connection pool etc which will change when they will be useful, but will make the transfers less likely to be CPU-bound when you can spread them out over a larger set of cores/CPUs.

            Which the right design decision is for you, is not easy for us to tell.

            Source https://stackoverflow.com/questions/44739178

            QUESTION

            memory_get_peak_usage(true) PHP and Virtual Memory Size resource usage are very different
            Asked 2017-Oct-04 at 14:04

            I have a PHP script which runs many http requests via curl - I use a variation on Rolling Curl (curl_multi) so that the requests can be run simultaneously. The script runs every few minutes with cron.

            It is on a VPS and I received some 'Excessive resource usage' warnings from lfd (ConfigServer Security & Firewall) because the resource usage of the script went over the threshold of 512MB.

            An example notification is:

            Resource: Virtual Memory Size

            Exceeded: 582 > 512 (MB)

            Executable: /path/to/php-cgi

            Command Line: /path/to/myscript.php

            So I upped the threshold to 800MB and recorded the memory usage of the script using memory_get_peak_usage(true) every time the script runs.

            However, the results from memory_get_peak_usage(true) are consistently 2MB... which is nowhere near the Virtual Memory usage as seen in the warning.

            Note - only one instance of the script runs as multiple instances are prevented using flock.

            So what am I missing?

            Update - virtual memory usage also greater than php.ini memory_limit

            After upping the threshold to 800MB I still get occasional notifications from lfd. I also checked the php.ini settings and memory_limit is set to 256MB - in theory the script wouldn't run if it was using more than this. From this I am guessing that either:

            a) It is not PHP that is using the memory (could it be MySQL or CURL - is the memory used by these included in the value frommemory_get_peak_usage(true)?)

            b) I'm not getting an accurate figure from lfd

            Second Update - memory used by MySQL is not included in memory_get_peak_usage(true)

            I suspect this is the issue - however I'm not sure what exactly CSF includes in resource figure. I will look into making the MySQL requests more efficient and see how that effects things.

            ...

            ANSWER

            Answered 2017-Oct-04 at 14:04

            PHP's memory_get_usage family of functions tracks the state of PHP's internal memory manager, which is responsible for all memory directly used by things like PHP variables. This is also what is limited by the memory_limit setting - after the limit is reached, the internal memory manager will refuse to claim more RAM from the OS.

            However, not all the RAM used by your process is allocated via that memory manager. For instance, third party libraries like CURL or the MySQL connection library will have memory allocation completely independent of PHP, because they are effectively separate programs being executed by the PHP engine. Another example is that opening a file might cause it to be mapped into memory by the OS kernel, even if you never read its contents into a PHP variable.

            This talk by Julien Pauli at PHP UK a few years ago goes into more details on the different types of memory usage, and how to measure them.

            Source https://stackoverflow.com/questions/46528200

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install curl_multi

            You can download it from GitHub.
            PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/woondroo/curl_multi.git

          • CLI

            gh repo clone woondroo/curl_multi

          • sshUrl

            git@github.com:woondroo/curl_multi.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Command Line Interface Libraries

            ohmyzsh

            by ohmyzsh

            terminal

            by microsoft

            thefuck

            by nvbn

            fzf

            by junegunn

            hyper

            by vercel

            Try Top Libraries by woondroo

            dig

            by woondrooPHP

            ip_intercept

            by woondrooPHP

            pure_project

            by woondrooPHP

            dig_file

            by woondrooPHP

            lcm_algorithm

            by woondrooPHP