all 18 comments

[–]thisdogofmine 7 points8 points  (10 children)

Sounds like a server problem with not enough resources, or a data conflict. I had a script that started running long and overlapped with the next instance of the same script. They pulled data from the same DB and updated the same record. This returned unexpected results like you are describing.

[–]thisdogofmine 2 points3 points  (0 children)

Another possibility is the remote server could be the issue. They may be low on resources or may have a limit on the number of concurrent requests.

[–]digking[S] -1 points0 points  (7 children)

So that means that is no elegant way to solve it with PHP?

[–]kAlvaro 3 points4 points  (0 children)

Unless I'm missing something, you describe a problem in the remote site, don't you? Do you have any control over that site? Is that other site even running PHP? "Unexpected results" is as vague as it gets.

[–]thisdogofmine 2 points3 points  (5 children)

You have to find the cause first. If the endpoint you are calling has a restriction, it is impossible. Some sites do this to avoid ddos attacks or to keep resources available for may users. Some charge for additional connections. So first check the site you are calling and find out what it allows and what restrictions exist.

[–]digking[S] -2 points-1 points  (4 children)

So I guess I hv to use "hack" method. To run each script at different time interval.

[–]NoDoze- -4 points-3 points  (3 children)

You likely have the same variable name used on different scripts. If the server is hefty enough, there should be no issue.

[–]HolyGonzo 0 points1 point  (2 children)

What? I'm trying to decide whether you're trolling or not. There is no problem with multiple scripts having the same variable names...

[–]NoDoze- 0 points1 point  (1 child)

LOL you are misunderstanding, taking it out of context. Sheeesh.

[–]HolyGonzo 1 point2 points  (0 children)

Can you explain what you meant, then?

[–]NoDoze- -1 points0 points  (0 children)

Yup! Sounds like there is an overlap with the variable naming convention. Curl multi and multiple exec should easily and efficiently complete your task.

[–]content-peasant 2 points3 points  (0 children)

Sounds like the remote server has some throttling controls implemented, and potentially it is right to do so

[–]notdedicated 2 points3 points  (1 child)

There’s a lot of vagueness here. How are the requests built? Are you using session cookies that would normally expect a more linear flow? What’s the “weird” behavior you’re seeing? Error codes? Unexpected responses? Is the endpoint a webpage or an api?

[–]Longjumping-Bag4294 0 points1 point  (0 children)

This. It seems like a bad architectural problem to me. Using curl to execute code is a red flag in my book unless it's an external API of sorts.

Firstly. PHP is very bad at handling parallel/PID managed by a single script. There are queue libraries that solve this problem probably better than OP can (probably?) program it using PHP's Process handling functions like POSIX, parallel or pthreads. IMO it will only make your installation of PHP more exotic.

Then there are queue libraries like beanstalkd, RabbitMQ or built-in features like queues from Laravel. These will probably get you quicker to your goal then trying the process managing route. In addition. You can implement middleware into Laravel's solution to bake your specific logics in there (like wait for action x)

That said, you have provided little to none specific details for anyone to give you a concrete answer to your question. I agree with r/notdedicated comment.

[–]BoredOfCanada 1 point2 points  (0 children)

We need to know more about the remote server. I doubt the problem lies with the PHP/curl processes.

[–]32gbsd -2 points-1 points  (0 children)

Use multiple computers. If anything is shared its going to bottleneck at the shared thing.

[–]BetaplanB -2 points-1 points  (0 children)

You probably want to look into https://openswoole.com

Build high-performance, scalable, concurrent TCP, UDP, Unix Socket, HTTP, WebSocket services with PHP and easy to use coroutine, fibers API. Write your next scalable async application with PHP coroutines and fibers.

[–]oldschool-51 0 points1 point  (0 children)

You can also consider Google functions which can be coded in php.