Welcome Guest, Not a member yet? Register   Sign In
  40 Tips for PHP Optimization
Posted by: El Forum - 10-15-2007, 10:14 AM - No Replies

[eluser]Michael Wales[/eluser]
40 Tips for PHP Optimization

Some of my favorites (many of these are mentioned in the EllisLab Developer Guidelines as well):

Quote:9. See if you can use strncasecmp, strpbrk and stripos instead of regex

10. str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4

15. Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.

24. Surrounding your string by ' instead of " will make things interpret a little faster since php looks for variables inside "..." but not inside '...'. Of course you can only do this when you don't need to have variables in the string.

29. Use ip2long() and long2ip() to store IP addresses as integers instead of strings in a database. This will reduce the storage space by almost a factor of four (15 bytes for char(15) vs. 4 bytes for the integer), make it easier to calculate whether a certain address falls within a range, and speed-up searches and sorts (sometimes by quite a bit).

30. Partially validate email addresses by checking that the domain name exists with checkdnsrr(). This built-in function checks to ensure that a specified domain name resolves to an IP address. A simple user-defined function that builds on checkdnsrr() to partially valid email addresses can be found in the user comments section in the PHP docs. This is handy for catching those occasional folks who think their email address is ‘[email protected]’ instead of ‘joeuser@Php.net’.

32. Learn to love the ternary operator.

40. When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.


  Project Management and CRM Application
Posted by: El Forum - 10-15-2007, 07:42 AM - No Replies

[eluser]SethG[/eluser]
I have begun creating a simple job/project management and crm system in Codeigniter as a foundational system to run a graphic design studio - though should certainly have implications to other fields. Basically, we have been interested in basecamp and highrise and similar types of offerings but felt that there was not an integrated solution that had the type of features we needed, so having built a similar custom solution before and having been interested in Codeigniter, I thought I would give it another go.

Some highlights include:

- Basic job tracking system
- Basic Invoice System that allows for the creation of invoices, invoice line items, and payments
- Organization/people management
- Basic Time Tracking for jobs/projects
- Notes system to add notes to Jobs, Organizations, People, Invoices
- Task system to add tasks that are related to jobs, organizations, people, invoices
- Starting to build in a basic security and access model - currently customizing to distinguish between access as an administrator from access for a freelancer. Would like to continue to evolve this to allow some sort of job/project access to clients as well as access to payment/invoice reports to clients.

So I am sharing what I am up to with the codeigniter community as if there are others of you out there that are interested, I would be open to exploring how to make this a communal project.

There is little to no documentation currently, though I have done some code cleanup to try and make my approaches as consistent as a I could. Working alone and juggling many other higher priorities likely means more needs to be done in these regards. I have also never setup or have been a part of a communal development project though I have started using Trac and SVN with this project through a hosted site/service called assembla. In other words to make a communal project work, I would need a fair amount of leadership help.

Also, this would have to be approached with some degree of seriousness as this is a critical business operations tool.


  Exceeding memory_limit - Image Manipulation Class
Posted by: El Forum - 10-15-2007, 07:10 AM - No Replies

[eluser]Unknown[/eluser]
Hello Everyone!

I've got a problem whilst trying to use the image_lib.

As you can see below im using it in a foreach loop so that every file in the specified folder is turned into a thumbnail in a different folder.

The actual creation of the thumbnail works fine but I would have thought that after each pass through the loop it should release the memory once it's done the processing and then start a fresh, but it seems to just keep adding to the memory and causing this error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 5120 bytes) in D:\durham\work files\websites\DesignJunkie\system\libraries\Image_lib.php on line 1140

I know that i could increase the size in the php.ini file but with the amount of files that need to be put through this function i would have to put it stupidly high.

Is there any problem in my codeing or any other way around this problem?

Cheers

Durham

CODE:


$photofile = get_filenames('./web/photoshoots/'.$data['shootid']);

foreach ($photofile as $value)
{
$clientphotos['image'] = $value;

//CREATE THUMBNAILS
$this->load->library('image_lib');

$config['image_library'] = 'GD2';
$config['source_image'] = './web/photoshoots/'.$clientphotos['shootid'].'/'.$clientphotos['image'];
$config['new_image'] = './web/photoshoots/'.$clientphotos['shootid'].'/thumbnails/';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 170;
$config['height'] = 120;

$this->image_lib->initialize($config);

$this->image_lib->resize();

//echo $this->image_lib->display_errors();
//END THUMBNAILS
}


  database config file
Posted by: El Forum - 10-15-2007, 06:37 AM - No Replies

[eluser]cinewbie81[/eluser]
Hi all,

The following is my setup.php controller clas:

Code:
class Setup extends Controller {

function Setup()
{
  parent::Controller();
  $this->load->helper(array('url','form','setting'));
  $this->load->model('dbmodel', 'sql', TRUE);
  $this->load->database();

}
    
function index()
{
  $this->load->dbutil();
  if ($this->dbutil->create_database('payroll'))   {
      echo 'Database created!';
  }
}

}


And the following is my database.php config:

Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "password";
$db['default']['database'] = "payroll";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";

When function index() loaded, the following error message prompted out:
"Unable to select the specified database: payroll"

This error is because I bind the value 'payroll' to $db['default']['database'] in my config file. It can be easily fixed if i manually query 'Create Database payroll' in prior, but i don't want it to be this way cause i don't want all my client have to manually create the database first before they can use the system. Any solution ??


  removing ? from urls
Posted by: El Forum - 10-15-2007, 05:10 AM - No Replies

[eluser]bkozora[/eluser]
What I'm attempting to do is remove the ? from my CI urls. I've got it omitting index.php, but my urls are rather ugly, appearing like this:

http://76.12.66.93/?projects
http://76.12.66.93/? - returns the default, my home page

How can I get http://76.12.66.93/projects to correctly direct to my projects controller?

I've been fiddling with this for a couple hours over multiple days now, and haven't seen any solutions that fit, if this is a duplicate of another post my sincerest apology's, I couldn't find it on the forums.

Thanks!


  missing Code file...
Posted by: El Forum - 10-15-2007, 03:55 AM - No Replies

[eluser]Hitesh Kapadia[/eluser]
Hi..

Code file on link http://www.thzero.com/programming/codeig...sentry.zip
is missing can any one send me code zip file.

thanks


  Navigation - highlight current menu tab
Posted by: El Forum - 10-14-2007, 09:48 PM - No Replies

[eluser]123XD[/eluser]
Hi all,

With the CI, how can I highlight the current menu tab??

Just like the CI home page.

Is there any easy way to do it with CI, or just code as the normal way?

Cheers


  anchor function
Posted by: El Forum - 10-14-2007, 09:31 PM - No Replies

[eluser]cinewbie81[/eluser]
Hi all, i'm very new to CI.. Can anyone help with my following question:

I want to have an image, after clicked on that image i want it to go to the controller's function .. So instead of write :

anchor('dbbackup/backup', 'Backup'), i want something like

anchor('dbbackup/backup', 'img src = '/home/eddy/myicon.jpg') - Of course this doesn't work ...


anyone can tell me how ?

thanks


  backup db
Posted by: El Forum - 10-14-2007, 09:20 PM - No Replies

[eluser]cinewbie81[/eluser]
Hi all, I'm new here..

I use CI build in library to do my database backup, and the code is as following:

$this->load->dbutil();
$prefs = array(
'ignore' => array('my_ignore_table'),
'format' => 'txt',
'add_drop' => FALSE,
'add_insert' => TRUE,
'newline' => "\n"
);

$backup =& $this->dbutil->backup($prefs);
$this->load->helper('download');
force_download('mybackup.sql', $backup);
The code aboe is working, but it will always backup the file and download it to my Desktop (through force_download function) .. But what i want now is to create a new folder each time i do a backup, and then download the backup file to the new created folder. Is that any way for me to do it ? Hope u guys can help, thanks in advance


  Navigation and subcategory
Posted by: El Forum - 10-14-2007, 07:29 PM - No Replies

[eluser]Référencement Google[/eluser]
Hi,

I would like to get some advices before starting doing this:
I have in a backend an "edit profile" page where I can edit user informations.
As it has a lot of things, I organised things in Tabs, and each tab have a different form.

Let's say for exemple, Tab 1 is for editing public profile infos, Tab 2 for the photos of the member, Tab 3 his videos, and Tab 4 some private infos

In this, I have a common part to all tabs that show a small thumbnail, the member name and some extra infos (let's say a small resume)

My url looking like that to reach the profile editing:
http://www.website.com/admin/profiles/edit/14 (where 14 is the profile ID)

How should I organise controllers functions and views that each forms post and validate to a specific fonction? Wich kind of Url would I have? I am not really sure on how to do things. (I was think of having url like: http://www.website.com/admin/profiles/edit/14/tab1

Here is a screenshot so maybe this help you to understand what I want to do:
http://www.imageultra.net/images/eliteme...enshot.jpg

Thanks for any help or advices


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Update from 4.6.0 to 4.6....
by FlavioSuar
Today, 04:17 AM
Setting baseURL in Regist...
by petewulf1
Today, 03:20 AM
Sessions old files are de...
by InsiteFX
Yesterday, 10:30 PM
Ajax post failing with Ty...
by PaulC
Yesterday, 12:23 AM
intermittent smtp failure...
by InsiteFX
05-11-2025, 11:30 PM
MVC vs MVCS vs CodeIgnite...
by FlavioSuar
05-10-2025, 10:33 AM
CodeIgniter Shield 1.0.0 ...
by timesprayer
05-10-2025, 05:22 AM
Website Traffic Drop Afte...
by InsiteFX
05-10-2025, 04:23 AM
Magic login link not work...
by InsiteFX
05-10-2025, 04:16 AM
Is codeigniter 5 upco...
by InsiteFX
05-10-2025, 04:10 AM

Forum Statistics
» Members: 145,773
» Latest member: nhacaiuytin1234
» Forum threads: 78,388
» Forum posts: 379,447

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB