bug-o-matic avatar image
bug-o-matic asked

How can I set maximum threads to 18?

Hi. I'd really like to submit my app for a compatibility check, but I'm stumped on the maximum threads requirement. How can I limit the maximum threads to 18 in PHP? Does this mean that only 18 users of my app can make a call at one time, or is this 18 threads per call? Any information and/or help would be appreciated.  Thanks.

10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

helios825 avatar image
helios825 answered

I wouldn't worry about it too much in PHP. Unless you're forking new threads in PHP (something I barely know about myself), then you're dealing with 1 thread per PHP session -- essentially 1 user = 1 thread.

Chances are you won't be running up against that 18 max. I have a hunch that the 18 max is more meant for locally executed apps, than for server-side PHP scripts. Unless you get hammered with traffic, if your PHP scripts have a reasonable timeout value (using cURL, for example, and settings timeouts of a few seconds), you're probably good to go.

If you're using distributed client-side apps in Javascript, I would imagine eBay would make allowances for that (via multiple IP addresses perhaps) such that 18+ users could be using your app simultaneously.

But you're using PHP, and I figure that you're making server-side API calls based on website user input, right? Just say in your application that having 18 simultaneous users is very unlikely, and since you're using reasonable timeout values, the chances of 18 overlapping executing calls is rare.

If webjustice reads this, he might be able to recommend some server tweaks, like Apache config lines, to limit sessions, or something like that...


· 1
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Threads means different things to apache, PHP and eBay API terms. On Apache, one user might use 6 threads/connections to retrieve images, but for a relatively short timeframe. Connections get managed by Apache.  You can't limit connections in Apache without breaking users' ability to download images in parallel. If you did limit threads somehow, and users consumed them all, you'll likely deadlock trying to get a connection to eBay until the server disconnected the users.


What you're really concerned about is 18 simultaneous API calls from PHP. As Helios said, you're single threading under PHP unless you make an effort not to, so you'd have to have 18 users hit at once. Not likely to happen on a low volume server.


You'd have to monitor the API calls using semaphores or shared memory counters to control it. Find out if it's an issue first. Unless you are running a high volume site it's very likely your only seeing one or two simultaneous connections.


If you have console access, use netstat to count open connections to eBay. (There may be other ways to do this.) I rarely see more than half dozen simultaneous connections actually active.

   netstat | grep -i ebay | grep -ic established

Best approach this from an app standpoint instead of trying to monitor threads. You can load balance if you are running multiple sites by getting more servers. The more sites you have on one server the more likely it is that you'll have 2 users and 16 instances of GoogleBot active at any given time.


For normal sites:

- Implement a caching scheme to lighten the API load.

- set crawl delays in robots.txt to throttle googlebot

- flag known bots during script setup based on IP or UA and always serve them cached content or block them, never go to the APIs to satisfy a bot if you can avoid it. The bots won't display your eBay content for days anyway, and then not anything directly of use to your users.


If you get too high volume, you need to decouple the users from the API call process. Serve items from a database or cache, and fetch from eBay in the background with a cron job or long running process. Or use PHP semaphores or shared memory to track active API calls and wait or abort when you hit the limit.


Or move the API/RSS requests to the client side or proxy them thru multiple servers. If you are using Trading, there is a limit of 3 simultaneous calls client-side.



0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.