cURL Error (28) - troubleshoot JSON request / PHP

Closed Posted Mar 25, 2014 Paid on delivery
Closed Paid on delivery

Hi,

I have a PHP program that uses JSON and cURL to request data to be written to a txt file. When I execute it, I am getting the following error:

cURL Error (28): Operation timed out after 201 milliseconds with 0 bytes received

Here is my code:

if (!isset($_GET['foo'])) {

// Client

$pIds = array("All");

$data = array("apiToken" => "apitoken-3D", "productIds" => $pIds);

$data_string = json_encode($data);

//echo $data_string;

$ch = curl_init('http://myurl/WriteProductData');

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_NOSIGNAL, 1);

curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

'Content-Type: application/json',

'Content-Length: ' . strlen($data_string))

);

$data = curl_exec($ch);

//var_dump(json_decode($data, true));

$curl_errno = curl_errno($ch);

$curl_error = curl_error($ch);

curl_close($ch);

if ($curl_errno > 0) {

echo "cURL Error ($curl_errno): $curl_error\n";

} else {

echo "Data received: $data\n";

} else {

// Server

sleep(10);

echo "Done.";

}

Above is not the real API key, etc. but just wanted you to see the code.

Please advise how to troubleshoot this, and what to do to resolve this issue. We can make adjustments on the server if necessary. Please respond back and let me know how much experience you have with PHP/Curl.

THANKS!

PHP

Project ID: #5716370

About the project

21 proposals Remote project Active May 1, 2014

21 freelancers are bidding on average $28 for this job

toinnisfree

A proposal has not yet been provided

$35 USD in 0 days
(585 Reviews)
8.0
rajeshsonisl

Hello, With 99% completion rate, 650+ successfully completed projects, and a 5.00 reputation (maximum possible, 5.0) (Yes, not even 4.99 average rating, can be verified on my profile page !!)... you can never go wro More

$43 USD in 1 day
(465 Reviews)
7.4
tlchung

skilled in curl, i can do the fix for you. skilled in curl, i can do the fix for you. skilled in curl, i can do the fix for you.

$24 USD in 1 day
(190 Reviews)
7.0
webxtor

Hello. The error simply means that the remote server which provides the requested data is not currently available. The URL of it you can see in this line (in your real code of course): $ch = curl_init('http://myurl More

$30 USD in 0 days
(109 Reviews)
5.6
shashanksingh198

Hi, I can get this debug and working for you with perfection and on time. I am a Software Developer with over 4.5 years of experience in LAMP technology. I have worked with various technologies like CakePHP, Ma More

$30 USD in 1 day
(30 Reviews)
5.0
sunsriinfosys

Hi, I have over 13 years of Experience in software design, development and implementation of various commercial applications in Client/Server environment, Web and ERP applications using C# 1.1/2.0/3.5, ASP.Net, VB.N More

$25 USD in 0 days
(16 Reviews)
4.4
lp1051

Hello, your CURL request and settings seems to be OK. So here are my tips: 1. CURLOPT_TIMEOUT_MS = 200, are you sure you're not too hard here? 200ms is really very SHORT time, try to increase it to 1000 (= 1 sec), a More

$29 USD in 1 day
(4 Reviews)
4.2
netmente

A server administrator with 7 years of experience and a PHP developer with over 10 years of experience are available here to troubleshoot this issue. Please share the details if interested.

$25 USD in 1 day
(12 Reviews)
4.1
projectdolphin

Your problem is that cURL is set to timeout after 200 milliseconds which is far to short. Remove this line totally curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); or set the value to something higher than 200. I personall More

$10 USD in 0 days
(7 Reviews)
4.0
GeorgeKazi

Hi! I have had a similar problem with my curl scripts. If you have Teamviewer handy I can begin working on this for you right now. Thanks, George

$30 USD in 0 days
(9 Reviews)
3.9
viptayninh

Hello, I found your job post and I’m very interested in your project. As an experienced PHP, Curl. You can check my profile to see my project about curl I think you’ll find I have the skills you’re looking for. I More

$34 USD in 1 day
(12 Reviews)
3.4
Devo7

Hello, You are telling CURL that the script have to stop after 200ms, so this is why you are getting the error at 201ms, I can't tell like that what's the error, I have to see the error that CURL return with curl_er More

$25 USD in 1 day
(3 Reviews)
3.3
mwain

Hi, You need to change - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); 200 millisecond timeout for a cURL request is not enough. I would recommend increasing that to 2000 milliseconds (2 seconds) maybe more depen More

$35 USD in 1 day
(3 Reviews)
3.3
sandeepgeca

Hello I have done many CURL POST PHP Script. Seems that there is only 1 line is to be added to fix ur issue. So give me UR Original URL. I will show you it is working. If its works then paid me else no Than More

$25 USD in 1 day
(2 Reviews)
1.7
ahmedulde

I have worked on a PHP project before. All i need is a detailed information about the work to be done and ill get the job done. Given this opportunity i wont disappoint you.

$25 USD in 15 days
(0 Reviews)
0.0
chalantorn

I see from the code, then Try changing your code line curl_setopt ($ ch, CURLOPT_TIMEOUT_MS, 200); Change the variable value CURLOPT_TIMEOUT_MS is 300

$10 USD in 1 day
(0 Reviews)
0.0
Bondaf

Hi! You can try to play with this string curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); 200ms seems to be too short timeout. For example, replace this: curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); by this: curl_setop More

$20 USD in 1 day
(0 Reviews)
0.0
misha777

Предложение еще не подано

$10 USD in 0 days
(0 Reviews)
0.0