Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 681267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:27:53+00:00 2026-05-14T01:27:53+00:00

I have a collection of PHP scripts that are extremely CPU intensive, juggling millions

  • 0

I have a collection of PHP scripts that are extremely CPU intensive, juggling millions of calculations across hundreds of simultaneous users.

I’m trying to find a way to speed up the internals of PHP variable assignment, and looping sequences vs C.

Although PHP is obviously loosely typed, is there any way/extension to specifically assign type (assign, not cast, which seems even more expensive) in a C-style fashion?

Here’s what I mean.

This is some dummy code in C:

#include <stdio.h>

int main() {
unsigned long add=0;

for(unsigned long x=0;x<100000000;x++) {
    add = x*59328409238;
}
printf("x is %ld\n",add);

}

Pretty self-explanatory — it loops 100 million times, multiples each iteration by an arbitrary number of some 59 billion, assigns it to a variable and prints it out.

On my Macbook, compiling it and running it produced:

lees-macbook-pro:Desktop lee$ time ./test2
x is 5932840864471590762

real    0m0.266s
user    0m0.253s
sys  0m0.002s

Pretty darn fast!

A similar script in PHP 5.3 CLI…

<?php
for($i=0;$i<100000000;$i++){
    $a=$i*59328409238;
}
echo $a."\n";
?>

… produced:

lees-macbook-pro:Desktop lee$ time /Applications/XAMPP/xamppfiles/bin/php test3.php
5.93284086447E+18

real    0m22.837s
user    0m22.110s
sys  0m0.078s

Over 22 seconds vs 0.2!

I realize PHP is doing a heck of a lot more behind the scenes than this simple C program – but is there any way to make the PHP internals to behave more ‘natively’ on primitive types and loops?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:27:53+00:00Added an answer on May 14, 2026 at 1:27 am

    The short answer is no, it is not possible to speed up PHP code in the manner that you desire. It is almost certainly better to optimize your code so you don’t have to do such a heavy numerical operation in the first place.

    The long answer is that there are two things you can do if you decide to do things the hard (ill-advised) way.

    • You can write your code as an extension to PHP, in C.
    • You can use something like HipHop
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.