Curl_init ()

Source: Internet
Author: User
Curl_init () I used curl_init () to pass the xml document.
--
$ SQL = "select aa from bb ";
$ N = $ DB-> ExecSQL ($ SQL );
While ($ DB-> Fetch ()){
$ Md5 = md5 ($ SRC. "& key = 6c3d80558fec2784b20a95863dca9458 ");
$ WEB = new WEB_SERVICE ($ HOST, 80, $ URL, "POST ");
$ WEB-> addPara ("para_xml", $ SRC );
$ WEB-> addPara ("MD5Data", $ md5 );
$ WEB-& gt; addPara ("customersid", "10058 ");
$ Ret = $ WEB-> run ();
$ WEB-> close ();}

Rough writing of the Run () function
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, "http: //". $ this-> IP. $ this-> URL );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ this-> PARAMETER );
$ Ret = curl_exec ($ ch );
Curl_close ($ ch );

Problem: 1000 pieces of data are found in SQL statements, but 10 may fail. If the 10 unsuccessful data packets are sent again, the transfer is successful again.
I found that when the page is repeatedly connected in a loop, sometimes the connection fails, that is, $ ret = $ WEB-> run (); a null value is returned. Therefore, the transfer was not successful.
How can this problem be solved ??
Do I need to add sleep () after each data transmission to control the trigger time of repeated connections?


Reply to discussion (solution)

You can try it with sleep.

You can use curl_getinfo to check whether the transfer is successful.
You can also collect all the data for one-time transmission.
You can also transmit data in multiple ways (curl_multi ).

Each interface can receive up to 50 packets at a time. The company throws more than 1000 transactions at a time. Therefore, it is unlikely that data will be discarded at the same time. Today, we will try sleep () to see the effect.

Sleep () still fails.

Are there other solutions for moderators?

You should record the status, and resubmit all the completed items.

I told you all about the solution. if you don't test it, you will not be able.
Who will step on you?

Thank you. In a rather stupid way, if the connection fails in the next request, close the post

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.