Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
Is it bad to put all my Ajax code in a single PHP file?

Am working on a huge project that does many Ajax call, I have just only one file name ajax.php, in this file is all my PHP codes for Ajax. I also have a single javascript file, named function.js, this also is the only Javascript file I have, all my JS scripts are there and I have just only one form function that processes all the forms in the whole application via Ajax, any form I give the class "formprocessor" would be processed through the form function in my javascript.

I feel having a single file and multiple users accessing it concurrently would lead to some speed issues when the users are many.

I am thinking of creating many PHP files for my Ajax, i.e. each page would have it's own PHP file for Ajax call. Do I really need to do this?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I have just only one file name ajax.php, in this file is all my PHP codes for Ajax. I also have a single javascript file, named function.js, this also is the only Javascript file I have.

It is definitely not good in terms of code maintainability and readability.
Every time you need to make any changes in your system, you modify this file. Also, it is you who knows where everything is located in this file, but if you give this code to another developer, then he will have a headache.

At least, you can separate every AJAX request handler to a separate file:

/handlers/PingHandler.php
/handlers/GetUserHandler.php
index.php

In index.php you can include all handlers and pass a request to a given handler. It will make code readable, and if you need to change GetUser functionality or add new, you only need to modify / create one file.

Or you can include all common things like database connections, checks, validations, authentication etc. to separate file, and then create pages which handle the request:

/include/database.php
/include/auth.php
ping.php
get-user.php

ping.php and get-user.php can include necessary php files and work with database / auth etc.

I feel having a single file and multiple users accessing it concurrently would lead to some speed issues when the users are many.

It absolutely doesn't matter if users access different files or one.
Web server handles this for you, there is nothing about performance you should worry about.

I am thinking of creating many PHP files for my Ajax, i.e. each page would have it's own PHP file for Ajax call.

It is a good idea. If you really feel that project structure is not convenient, not extensible, not supportable, and brings you problems, then refactor it if possible.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda