PHP curl code stops working after a few requests Cent OS 7 server

Posted March 6, 2018 3k views

I created a droplet in Digital Ocean and I have a code in PHP that uses curl to scrape a specific page.

When I created the server and configured it, the code works fine, but after a few requests it stops working. The curl doesn’t respond with the correct page, looks like there was a redirect to a wrong page.

I tried to destroy the droplet and start all over again, this time I created a snapshot of the droplet with code working, again after a few requests it stops working, I tried to restore to the snapshot, but it doesn’t work. Does anyone know what is happening? I think is some wrong or missing configuration, but I don’t figure out what is wrong.

I am using CentOS 7, apache, php 7.2

P.S.: The code works fine in other server that I use in a shared server in Hostgator, and works fine in localhost, too.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Can you share the details of what you are seeing when curl succeeds in pulling the requested document as well as what you are seeing when it fails?

My first thought was that the server you are scraping is using tooling to auto-redirect or restrict clients after a certain number of requests with a Curl user/agent to prevent scraping. This not occurring from other computers makes this more unlikely but not impossible if the site admin decided to only do this for addresses in the IP space of public cloud providers (as Netflix and others do for VPNs). More information would be helpful in helping you figure out the root cause of this.

Hello ryanpq,

Thank you for your reply, I will try to explain what is occurring below.

When I post a request to “” with the correct parameters I expect to be redirected to “”, instead in digital ocean server when I post the request I am redirected to “”.

Below the class I use and the code I use to instanciate the class.


use of class

you can use the following “CNPJ” to test “45543915000181”

I put a var_dump and an echo on the return of curl in the class, you can try bellow, in the server hosted in digital ocean.