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

328
Visualizações
Methods for PHP API calls, less scripts vs multiple scripts

My app makes calls to my PHP API on my Apache server...as I continue to try to optimize both app and server calls I routinely am reading materials on best practices. But one topic I am having a challenging time finding good material for - proper api script management.

I have some PHP scripts that handle a single request from the app...meaning the script returns only one specific set of data. Others that have a few functions and even others that many functions that return data to the app.

IE:

   login.php:
     if (lType == 1) {
       return doLogin() ;
     } else if (lType == 2) {
       return doLogout() ;
     } else if (lType == 3) {
       return doReset() ;
     }

Then I have another script that returns bulk of all content the user will be interacting with:

prodIndex.php:
if (pType == 1) {
  return existingProds() ;
} else if (pType == 2) {
  return listProds() ;
} else if (pType == 3) {
  return newProds() ;
} else if (pType == 4) {
  return listProds() ;
} else if (pType == 5) {
  return buyProd() ;
} .... {
  return listProds() ;
} else if (pType == 15)
  return prodReview() ;
}

In login.php example, its just three quick easy functions totaling about 150 lines of code....but for prodIndex.php its 15 primary functions. Each return thisFunction() is quite extensive and the whole script is over 1600 lines long.

Three questions:

  1. Is it better to split all 15 prodIndex.php functions out into individual php scripts and have the app call each individually....or is it OK to keep them as is? How will the server handle a request to the main prodIndex.php file for pType == 8 versus the app requesting a specific file pType8.php? I suppose script load times will be somewhat faster for smaller files, but overall how will the server handle queue requests if all requests go to the same prodIndex.php file versus going to 15 different files?

  2. If its better to split them out....then should there be a primary file that then determines the incoming request and loads the secondary script...or just have the app call the secondary script directly?

  3. If splitting everything out into multiple scripts is best practice, is there any scenario where a single script serves just a few primary functions - like the login.php script?

My biggest concern in all of this is server response times, server congestion and server resources leading to potential timeouts or delayed responses to back to the app.

Thanks in advance.

over 4 years ago · Santiago Trujillo
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