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

carcleo's avatar

Loop breaking

I have the code:

The script dont arrives to return $sdc;, it break before.

The loop works fine, its breaking at the inserts.

If i put only the loop array, without the inserts, simuling the values, teh $src array out corretly.

How can i fix it?

0 likes
22 replies
tykus's avatar

Hard to say; is there an error/exception, or is it failing silently? Are any Model being created?

Are you sure all of the keys you are using to index into each $line exists? You are taking no steps to mitigate for missing/incorrect keys.

carcleo's avatar

@tykus yes 'cause this same script is running in other sistema and its working fine

Sinnbeck's avatar

@carcleo Then what error are you getting? If it never reaches the end, it must be throwing an error

carcleo's avatar

@tykus other things, if i create only the arra in the loop

$lines = [];
foreach ($reader as $line) {
  $lines[] = $line;
}

its arrives fine with all data of reader file

its say to me hat the problem is at the insertions

carcleo's avatar

@Sinnbeck then, its not show errors, neither on aba network.

But it go recording the data into database until break (stop)

tykus's avatar

@carcleo okay... and???

What is the outcome of running the method; again, is there an error/exception? If there is nothing in the browsere/CLI, did you check your logs for any hints?

carcleo's avatar

@tykus POST https://acl.com/updated/students 500 (Internal Server Error)

it run local, not internet (VirtualHost Apache)

look it:

https://photos.google.com/album/AF1QipO9qxEceGKZ7DhYNoGirRXRI27hp2gwz5ZmI2om/photo/AF1QipOFNGCIfotfyprbcUQZJqEEzJUbaOKifojoZvcy

i clean the apche log and next that run it, this is the out of log

Apache Log:

[Thu Feb 06 08:50:31.132025 2025] [php:error] [pid 1168:tid 1044] [client 127.0.0.1:52086] PHP Fatal error: Maximum execution time of 30 seconds exceeded in D:\web\php\acl.com\vendor\laravel\framework\src\Illuminate\Hashing\BcryptHasher.php on line 49, referer: https://acl.com/atualiza/alunos

I think that need group the inserts and to do a upser with it. But i dont know how to do once that, for exemple, the Student depends of user_id

tykus's avatar

@carcleo finally! There's your issue.

Maximum execution time of 30 seconds exceeded

Grouping inserts will not solve the problem. Push this work to a background job using a queue.

Mahmoud04's avatar

Hi @carcleo your code need some optimize try this and tell me if work

carcleo's avatar

@malmalah0 Not works, $reader is not a array, its a xls file but $line, (that is in $reader), it yes is a array. them, getExistingUsers() not will works fine

And this way that you do not works because the final array will have repetitions of disciplines and classrooms for each student to fill the array student_discipline_classroom

tykus's avatar

@carcleo your problem appears to stem from the amount of data you are trying to process; moving this task to a background job will give you more time to process the job (and without blocking the Response to the user).

carcleo's avatar

@tykus Not works

tykus's avatar

@carcleo "not works" in what context? I appreciate that English might not be your first language, but you need to try to explain what you have done differently?

carcleo's avatar

@tykus i out of foreach the called at database and do serious arrays.

next, i do array_chunk in this but the program, break inside foreach

tykus's avatar

@carcleo are you using a Queue; if yes, which queue driver is configured?

What is happening before this method; is there another long-running operation, e.g. a Request out to a third-party API?

carcleo's avatar

@tykus Request out to a third-party API? No.

before foreach, works fine

but when arrives more or less there 500 cicles od loop it breaks

Please or to participate in this conversation.