function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim AndersonJim Anderson 

5 connection limit to API, Application pooling in PHP

We are going to be using PHP to access the API and I was wondering how others have gotten around the 5 connection limit to the API.  Are you using some kind of application pooling?
msimondsmsimonds
What do you mean exactly?   What is the 5 connection limit > If I knew more about that I maybe able to help you

I have script that run updates on over 130,000 records that run on a cron script and they never fail
sfdcfoxsfdcfox
Each user ID can only have five connections at a time though the API. In this case, he's concerned that he'll get error messages if too many requests are made to his server at once. I would recommend using a semaphore on a file or system object. That way, the OS can enforce a five concurrent connection limit (extras block until they aquire or the page times out-- if this is a problem, I'd consider mirroring data on a local db or using app pooling). The php sem_* commands can be used to create a semaphore that provides the connection limit, so long as all processes using the API run on the same server.

~ sfdcfox ~
Jim AndersonJim Anderson

Thanks for the info!

Do you know if you can do application pooling with PHP5 running on IIS.  I dont see any info out there on it.  I was thinking I could just write my own with a DB table.  So as a request came in to access the api..it would check the table to see if there were 5 request already..is yes..it would loop until no..then insert a row..connect to the api...disconnect from the api when done..and remove the row.

sfdcfoxsfdcfox
You probably could do that, but that's why they have semaphores. A semaphore is an operating system-level object that doesn't require "looping" or any special constructs-- the OS will let each process know when it's turn is up. Also, this method is thread-safe, unlike querying a database, which may not be thread-safe if coded improperly.

For example, if both threads query the database at the same time, then commit an update at the same time, it is possible that you may overflow your connection limit. The correct method in this case would be to use an insert command that will fail if the maximum number of rows has been exceeded. Even so, polling is considered an inefficient and resource-intensive method that semaphores solves quite elegantly.

Try this link here: http://php.net/sem

They have the information you need to implement semaphores on the server of your choosing. I know very little of IIS, as I use Apache to run my personal web server. However, I am using a Windows system, which is supported by PHP for semaphores. However, I don't have PHP, either, I use Perl and Ruby. Best of luck with getting that to work. If I find anything else interesting, I'll let you know.

~ sfdcfox ~