Hey guys.

I am running a php script (locally) which runs through a loop several hundred times. Each time through the loop the same computation is done with the exception of two input variables being different. The input variables are obtained with a MySQL query based on the counting variable in the loop.

I used to run this program on an Ubuntu machine. The first iteration would take about 1 minute and each subsequent iteration took about 10 seconds. Now, on my Mac, each iteration takes the full minute. My guess would be that this has something to do with how Ubuntu managed the script in cache. I'm running PHP5, MySQL 5 and Apache 2.

Does anybody know how to make modifications to either my script or to my machine to store the program in cache?

Let me know if you need more info, and thanks.

Compare the php.ini's on your Mac and on your Ubuntu machine to see what the difference are. From your unintentionally vague description it's hard to tell what's going on exactly so the ini files are the best place to look.

Hmm. I checked the two php.ini files and they are exactly the same except for the memory_limit line.

Oddly enough, memory_limit was set to 16 in Ubuntu and 128 in OS X.

Do you know if php accelerators like APC or eAccelerator work when running scripts from the command line?

I don't believe so but it is possible that CLI and Apache PHP are using separate ini files. Type php --ini to see the ini files it is using.

I'm not positive yet but I think you may have just solved my problem. There are two php.ini files on my machine. One is at /etc/php.ini. The other is at /private/etc/php.ini. I was editing the private one before when I think I wan to be altering the regular one.

Thanks for your help! I'll post back here if the fix actually worked so hopefully someone else can be spared the trouble.

I lied. The two instances of php.ini are exactly the same. One thing I did notice is that the server timeout is set to 30 seconds, but when I run a script from the command line it is allowed to execute forever. Does this mean that php isn't seeing either php.ini file?

If that's not the case then I am absolutely stumped. The mac has a better processor (2.26 ghz core 2 duo instead of 2ghz core duo), better ram (2gb of ddr3 1067 instead of 2gb of ddr2 667), and the LAMP/MAMP servers on the two computers are set up identically.

Any help would be greatly appreciated. Thanks.

It's entirely possible that it's just a Mac thing. It's not like you're going to be running production code on a Mac so I wouldn't really worry about it. If you are thinking of for some stupid reason using your Mac as your server then end that thought quickly :)

FIGURED IT OUT! That took way too long though.

It wasn't just a mac thing, and it wasn't php. It was in the MySQL settings. For whatever reason, the default MySQL install had query_cache_size set to 0. I changed that value to 16MB (the value on my linux box) and now it works like a charm. I'm going to play around with increasing it some more too since my program is so read intensive.

Thanks for your help.

The first iteration would take about 1 minute and each subsequent iteration took about 10 seconds. Now, on my Mac, each iteration takes the full minute.

Thats a pretty slow operation. Are you sure you've optimized it well? Is the db tables well indexed? Are you using the correct storage type?

Do you know if php accelerators like APC or eAccelerator work when running scripts from the command line?

I don't see why they won't work.

I've written a simplistic PHP Object cache in pure PHP that you could try out. Only requirement is PHP Sockets.

http://code.google.com/p/php-object-cache/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.