Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

liyo21's avatar

Sending massive data to an API

Hello community.

I am trying to import a CSV data to an API and i getting this error: cURL error 52: Empty reply from server (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://IPAddress:3000/cl/back/subido/create

I tried sending data like this:

        $response = Http::post('IPAddress:3000/cl/back/subido/create',[
        'libre' => 'Esto es una prueba',
        'names' => 'Peter',
        'last_name' => 'Gutierrez'
    ]);

And it works

But when i extract data from a CSV doesnt

this is how i am doing

My Controller:

public function store(Request $request)
{
    /* Cache::flush(); */

    $file = $request->file('file');
    Excel::import(new CandidatosImport, $file);

	return back()->with('info','Successfull');
 }

My Import File:

public function model(array $row)
	{
    	$response = Http::post('IPAddress:3000/cl/back/subido/create',[
        'libre' => 'Esto es una prueba',
        'nombres' => $row[1],
        'apellidos' => $row[2],
        'email' => $row[11],
        'clave' => '123',
        'dia' => 5,
        'mes' => 2,
        'ano' => 2005,
        'rut' => 22222222,
        'dig' => '1',
        'genero' => $row[6],
        'cargo' => 'ALCA',
        'partido' => $row[8],
        'par_nom' => 'INDEPENDIENTE',
        'region' => $row[4],
        'provincia' => $row[3],
        'comuna' => '13202',
        'lista' => 'F'
        ]);
	}


public function getCsvSettings(): array
{
    return [
        'input_encoding' => 'ISO-8859-1',
        'delimiter' => ";"
    ];
}

I will appreciate if someone help me, please.

0 likes
4 replies
devingray_'s avatar

Would it be possible to edit the original question and use markdown to format the code for the Import Class, it is hard to read as a line of text.

Second, have you tried batching the requests.

https://docs.laravel-excel.com/3.1/imports/batch-inserts.html

This way you will not make an HTTP request for every row, but instead make an HTTP request for a number of rows at the same time.

You can then alter the api to handle the request, usually with an upsert function in mysql

liyo21's avatar

Hi. I followed your instruction but i got this message:

Symfony\Component\ErrorHandler\Error\FatalError Maximum execution time of 60 seconds exceeded

i configured the php.ini to increase the time but still have the same problem

My code:

	public function model(array $row)
	{
    		return Http::post('IPAddress:3000/cl/back/subido/create',[
        	'libre' => $row[0],
        	'nombres' => $row[1],
        	'apellidos' => $row[2],
        	'email' => $row[3],
        	'clave' => $row[4],
        	'dia' => $row[5],
        	'mes' => $row[6],
        	'ano' => $row[7],
        	'rut' => $row[8],
        	'dig' => $row[9],
        	'genero' => $row[10],
        	'cargo' => $row[11],
        	'partido' => $row[12],
        	'par_nom' => $row[13],
        	'region' => $row[14],
        	'provincia' => $row[15],
        	'comuna' => $row[16],
        	'lista' => $row[17]
    		]);
	}


public function batchSize(): int
{
    return 600;
}

public function uniqueBy()
{
    return 'email';
}

Please or to participate in this conversation.