Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

327
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!