Bug - preg_match(): Compilation failed: regular expression is too large at offset 32785

Bug occured after trying to add a new customer in Version 1.5.8 - Please help

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

ERROR - 2019-02-24 08:57:33 --> Severity: Warning --> preg_match(): Compilation failed: regular expression is too large at offset 32785 /home/ideatrad/public_html/invoice/vendor/codeigniter/framework/system/database/DB_query_builder.php 2413
ERROR - 2019-02-24 08:57:34 --> Severity: Warning --> Cannot modify header information - headers already sent by (output started at /home/ideatrad/public_html/invoice/vendor/codeigniter/framework/system/core/Exceptions.php:271) /home/ideatrad/public_html/invoice/vendor/codeigniter/framework/system/helpers/url_helper.php 564

Hi

Do you know what hosting enviroment you are working within? ( Apache / PHP etc )

Have you considered upgrading to v1.5.9 if it is safe to do so, and have a safe and secure backup?

Regards

1 Like

|Apache Version|2.4.38|
|PHP Version|5.6.40|
|MySQL Version|10.0.38-MariaDB|

Is updating the only way to solve the bug or? It shows each time when adding a new client.

It’s showing the error for a number of reasons.
They’re very technical, so i will spare them.

Solution 1 is to ask your host if you can go over to PHP7.

Solution 2 is to think about going to 1.5.9, but that depends on what your host says.

1 Like

changed the # PHP Version to 7.2.14 - same error.

A PHP Error was encountered

Severity: Warning

Message: preg_match(): Compilation failed: regular expression is too large at offset 32817

Filename: database/DB_query_builder.php

Line Number: 2413

Backtrace:

File: /home/ideatrad/public_html/invoice/application/core/MY_Model.php
Line: 157
Function: get

File: /home/ideatrad/public_html/invoice/application/modules/clients/models/Mdl_clients.php
Line: 249
Function: get

File: /home/ideatrad/public_html/invoice/application/modules/user_clients/models/Mdl_user_clients.php
Line: 75
Function: get_not_assigned_to_user

File: /home/ideatrad/public_html/invoice/application/modules/user_clients/models/Mdl_user_clients.php
Line: 99
Function: set_all_clients_user

File: /home/ideatrad/public_html/invoice/application/modules/clients/controllers/Clients.php
Line: 92
Function: get_users_all_clients

File: /home/ideatrad/public_html/invoice/index.php
Line: 325
Function: require_once

Befor changing anything elese pls just upgrade/update IP to the latest version.

The Offset of RegEx in PHP is just changable if you recompile it and this would not be the solution.

As this is a problem of the code itself changing the PHP version is not changing the code but using PHP 7 (and greater) is at least very good as its minimum requirement. BUT it can not solve the problem your having!

Pls do it like this:

  1. create a Backup of FTP and DB
  2. Update IP 1.5.8 to IP 1.5.9
  3. check if everything is working now.
  4. report back if it helped
  5. untill your not on the latest IP version support here is ‘limited’ as this will most probably fix all Bugs/issues your having. So updating is the first thing you should do.

Have you installed/modified something else which makes you installation not stock?

Regards, Martin

1 Like

Unfortunately just updated it to 1.5.9 and again the same bug occurs…

Then pls provide us a bit more infos about your system environment.

  • are you running IP from Webhosting or dedicated Hosting?
  • if Webhosting, at which provider?
  • On which Server/OS (and version) are you hosting IP?
  • do you use some hosting panel? If so which and which version?
  • do you have a normal PHP version or and home-brew one?
  • how many customers do you have?

If this happens this part will never be scalable.

I did never encounter this issue but maybe I cant even help here and the RegEx part just have to be made smaller, much smaller when it hits the offset 32785 :sweat_smile:
Hope someone else can help here as my skills with RegEx are limited.

If some of the Devs see this maybe this practice solves the problem and improves performance: LINK

1 Like
  • running IP from webhosting
  • superhosting.bg
  • |Hosting Package|SuperPro2017|
    |cPanel Version|70.0 (build 66)|
    |Apache Version|2.4.38|

PHP Version 7.2.14

|MySQL Version|10.0.38-MariaDB|
|Architecture|x86_64|
|Operating System|linux|

  • about 5000 customers

I personally think that Webhost for IP is not the best choice but this should not be the biggest problem.

Like I said: running big RegEx querys makes code un-scalable.
This in combination with 5.000 will make RegEx reach its limitations. (my own opinion)
I think making the RegEx part smaller would solve the issue.

I sadly have to say that I can not help you with this but hopefully some devs can. (@Severenth can you help here?)

Anyone help please?

It is difficult to help unless others are experiencing this too.
It looks like a simple enough query from the trace - I wonder what could be causing a query to be generated more that 32 K.

You can however, help us (if you have some coding savy).

The error is occurring in this file -
vendor/codeigniter/framework/system/database/DB_query_builder.php

If you are able to edit the file, let me know. I will suggest some code changes that might help us pinpoint the error.

It shows each time when adding a new client.

Is there anything unusual about the client data, for example a very large text field, or some value that is cut and pasted.

<?php defined(‘BASEPATH’) OR exit(‘No direct script access allowed’); ?>

You posted that error. That looks like a weird redirect. Can you tell me the following URLS

  • The URL before you clicked the button to add the client
  • The URL when the error shows,

Also, if you have slack, look me up so that we can go through some details of your applications.

1 Like

I can edit the DB_query_builder.php if you can tell me what to insert in it. Regarding the entered client data - it’s almost always just a simple email or the additional fields as city, VAT# address and so on - row in CP1251 encoding - none of them is longer than 3-4 words

https://www.deatrade.eu/invoice/ - before adding the customer
https://www.deatrade.eu/invoice/index.php/clients/form - after clicking the add customer button
https://www.deatrade.eu/invoice/index.php/clients/form - after adding the client the URL stays the same

In that file, look for this code (line 2407 on my version)

                            // Split multiple conditions
                            $conditions = preg_split(
                                    '/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i',
                                    $this->{$qb_key}[$i]['condition'],
                                    -1,
                                    PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
                            );

and replace it with

                        try {
                                // Split multiple conditions
                                $conditions = preg_split(
                                        '/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i',
                                        $this->{$qb_key}[$i]['condition'],
                                        -1,
                                        PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
                                );
                          } catch (\Exception $e) {
                             echo 'Caught exception: ',  $e->getMessage(), "\n";
                             print_r($this->{$qb_key}[$i]['condition']);
                             die();
                         }

This will stop the application dead in it’s tracks, but it will catch the error when it happens, and will print out the large condition that is being processed as part of the query.

It might also be a good idea to turn on debugging in the ipconfig.php file, which will then print some hints in the application/logs directory.

1 Like

I changed it and this comes as a message after adding a client /also turned on the debugging in ipconfig.php/log-2019-02-26.php (22.3 KB)

A PHP Error was encountered

Severity: Warning

Message: preg_match(): Compilation failed: regular expression is too large at offset 33105

Filename: database/DB_query_builder.php

Line Number: 2424

Backtrace:

File: /home/ideatrad/public_html/invoice/application/core/MY_Model.php
Line: 157
Function: get

File: /home/ideatrad/public_html/invoice/application/modules/clients/models/Mdl_clients.php
Line: 249
Function: get

File: /home/ideatrad/public_html/invoice/application/modules/user_clients/models/Mdl_user_clients.php
Line: 75
Function: get_not_assigned_to_user

File: /home/ideatrad/public_html/invoice/application/modules/user_clients/models/Mdl_user_clients.php
Line: 99
Function: set_all_clients_user

File: /home/ideatrad/public_html/invoice/application/modules/clients/controllers/Clients.php
Line: 92
Function: get_users_all_clients

File: /home/ideatrad/public_html/invoice/index.php
Line: 325
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/ideatrad/public_html/invoice/vendor/codeigniter/framework/system/core/Exceptions.php:271)

Filename: helpers/url_helper.php

Line Number: 564

Backtrace:

File: /home/ideatrad/public_html/invoice/application/modules/clients/controllers/Clients.php
Line: 104
Function: redirect

File: /home/ideatrad/public_html/invoice/index.php
Line: 325
Function: require_once

OK, I;m afraid I may have misled you. It looks like the try-catch has no effect on the preg_split function. Sorry about that.

You may have to do something more hackish, like displaying the variable at the top of the function each time it is called.

If I get a chance I will try to duplicate this on my side.

2 Likes

Anyway, thanks for the efforts. If you have an idea how to fix it please reply!

Can someone please check this bug and find a solution for it. The system is really useless this way.