Good day I'm trying to create some virtual cards with an array of json from a CSV file. The CSV file have 100 cards that I'm trying to create. If I try to post the full 100 lines in the csv file I get a 504 error. If I post it with only 10 lines the post is successful printing the response.
I'm hosting this on a shared hosting account. I cannot change the http.conf or any other apache configuration.
My CSV file
First,Lasy,DOB,Phone,Email,Address 1,Address 2,City,State,Zip,Country
John,Doe,1/1/2000,5555555555,something@example.com,123 something street,,Atlanta,GA,00000,US
Jimmy,Doe,1/1/2000,5555555555,something@example.com,123 something street,,Atlanta,GA,00000,US
My Code. . .
$handle = fopen('sgvc.csv', 'r')
$header = fgetcsv($handle);
while(($data = fgetcsv($handle)) !== false){
$sv = '{
"VirtualCards":[{
"FirstName":"'.$data[0].'",
"LastName":"'.$data[1].'",
"DateOfBirth":"'.$data[2].'",
"Phone":"'.$data[3].'",
"Email":"'.$data[4].'",
"ProfileAddress":{
"AddressLine1":"'.$data[5].'",
"AddressLine2":"'.$data[6].'",
"City":"'.$data[7].'",
"State": "'.$data[8].'",
"PostalCode":"'.$data[9].'",
"Country":"'.$data[10].'",
},
"GroupId": ""}]
}';
echo $sv;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sv);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: token ','Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);
}
fclose($handle);
}
My echoed json..
{ "VirtualCards":[{ "FirstName":"John", "LastName":"Doe", "DateOfBirth":"2/3/1981", "Phone":"5555555555", "Email":"something@example.com", "ProfileAddress":{ "AddressLine1":"123something rd", "AddressLine2":"", "City":"atlanta", "State": "GA", "PostalCode":"00000", "Country":"US", }, "GroupId": "123",}] }
{ "VirtualCards":[{ "FirstName":"John", "LastName":"Doe", "DateOfBirth":"2/3/1981", "Phone":"5555555555", "Email":"something@example.com", "ProfileAddress":{ "AddressLine1":"123something rd", "AddressLine2":"", "City":"atlanta", "State": "GA", "PostalCode":"00000", "Country":"US", }, "GroupId": "123",}] } //...array of json
I have tried to understand this. Such as putting this in data chunks or using stream_context_create. Is there a better way to do this such as 10 lines at a time?