Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #16343 [Router] Too many Routes ? #16386

Closed
wants to merge 1 commit into from

Conversation

jelte
Copy link

@jelte jelte commented Oct 30, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16343
License MIT
Doc PR N/A

Seems there is an issue when you have more than 7265 routes declared,
The routes are generated into the cached appDevUrlGenerator.php but php only loads the last 7265 elements of the array.

@Tobion
Copy link
Member

Tobion commented Oct 30, 2015

AFAIK php arrays are only limited my memory. So what does this solve?

@jelte
Copy link
Author

jelte commented Oct 30, 2015

I know, that's what I thought as well.

yet when I checked out https://github.com/AntoineLemaire/symfony-standard/commits/2.8, and I debugged the generated appDevUrlGenerator.php file by dumping the self::$declaredRoutes there were only 7265 routes in there instead of 20000+.

well after a bit of experimenting it seems the issue is that declaring the routes in the constructor instead of the class fixes it as well.

will make a test case to illustrate the issue.

@jelte
Copy link
Author

jelte commented Oct 30, 2015

you can find an illustration of the issue at http://khepri.be/test_appDevUrlGenerator.php ( source at http://khepri.be/test_appDevUrlGenerator.php.txt )

Basicly 2 identical arrays, one defined in the class and one in the constructor.
constructor shows the correct amount while the one in the class only has 1 element.

@mvrhov
Copy link

mvrhov commented Oct 30, 2015

# php /srv/www/test_appDevUrlGenerator.php.txt
32769 routes in constructor
32769 routes in class
# php -v
PHP 5.5.30-1.pi (cli) (built: Oct 19 2015 07:37:46)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans
with blackfire v1.6.0, https://blackfire.io, by Blackfireio Inc.

@jelte
Copy link
Author

jelte commented Oct 30, 2015

Seems to be an issue from php 5.6+

you can find a simplified example at https://gist.github.com/jelte/b2a9d73aec0211b07f6e

@mvrhov
Copy link

mvrhov commented Oct 30, 2015

Then I suggest reporting this. As it probably also doesn't work in 7.0

@Tobion
Copy link
Member

Tobion commented Oct 30, 2015

I confirm the bug in PHP 5.6.13. Seems pretty serious. Can somebody report it on PHP?

@jelte
Copy link
Author

jelte commented Oct 30, 2015

@sstok
Copy link
Contributor

sstok commented Oct 31, 2015

It was marked duplicate, and can't be fixed without breaking extensions.
20000+ routes? WTF! Why do you need this many?

Not using static may work also, but is a problem when you use something like ReactPHP and get allot of duplicated values in memory.

If you have this many routes, I guess one way to make it work is to separate them using a (I hope get this term right) binary-tree when the routes are split over multiple static variables (like done for the dumped matching).

@ghost
Copy link

ghost commented Nov 2, 2015

Known PHP issue for PHP5.6+ but it is only fixed in PHP7+.
https://bugs.php.net/bug.php?id=68057

[2015-03-23 17:51 UTC] bwoebi@php.net
Fixing this is an ABI break (so not really possible for 5.6.x). It's fixed in master (PHP 7+) though.

@jelte jelte force-pushed the bugfix/too-many-routes branch 2 times, most recently from 65bf924 to 8cb24cc Compare November 2, 2015 14:34
@jelte
Copy link
Author

jelte commented Nov 2, 2015

As this is a bug in PHP 5.6 which won't be fixed I made it an exception for that specific PHP version and only in case you have a large number of routes.

@sstok The large number of routes are due to a large amount of locales (30+) and translated uri's (check the ticket), With large sites, without some dynamic routes it can happen.

@stof
Copy link
Member

stof commented Nov 2, 2015

this needs to be covered by a test

$routes = $this->generateDeclaredRoutes();

// Fix for https://bugs.php.net/bug.php?id=68057 - Bug #68057 Incorrect parsing of big arrays in PHP 5.6.0
if (PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50700 && count($routes) > 32750) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 32750 ? Where did you get this value from ?

Also, please keep in mind that, if the size of the array is very large (maybe 50K), then count will also not work correctly. I just tested this on PHP 5.6 with an array of 56K elements. In that case, count said the array contained 23K elements.

So checking this with count won't work.... Unfortunately I can't think of an alternative implementation off-the-top of my head :( .

@jelte jelte force-pushed the bugfix/too-many-routes branch 3 times, most recently from 56ebc5b to 058f5fa Compare November 2, 2015 16:18
@jelte
Copy link
Author

jelte commented Nov 2, 2015

@stof Test has been added
@SoboLAN generateDeclaredRoutes is a string so obviously it didn't work, but counting the routes does. Also set the correct cut off number to 32769.
@sstok good point, added.

@@ -38,6 +38,45 @@ public function dump(array $options = array())
'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
), $options);

$routes = $this->generateDeclaredRoutes();

// Fix for https://bugs.php.net/bug.php?id=68057 - Bug #68057 Incorrect parsing of big arrays in PHP 5.6.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug is contained in 5.6.* not only 5.6.0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP_VERSION_ID >= 50600 && PHP_VERSION_ID < 50700
=> any version between 5.6 & 5.7, comment is the title of the bug report.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the impl. is fine, just the comment is not consistent with the code.

@jelte jelte force-pushed the bugfix/too-many-routes branch 3 times, most recently from 17991e0 to 0ee6033 Compare November 5, 2015 14:41
@@ -62,6 +62,9 @@ public function __construct(RequestContext \$context, LoggerInterface \$logger =
{
\$this->context = \$context;
\$this->logger = \$logger;
if ( null === self::\$declaredRoutes ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no space inside: if (null === self::\$declaredRoutes)

@nicolas-grekas
Copy link
Member

👍

@nicolas-grekas
Copy link
Member

Thank you @jelte.

nicolas-grekas added a commit that referenced this pull request Nov 25, 2015
This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16386).

Discussion
----------

Bug #16343 [Router] Too many Routes ?

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16343
| License       | MIT
| Doc PR        | N/A

Seems there is an issue when you have more than 7265 routes declared,
The routes are generated into the cached appDevUrlGenerator.php but php only loads the last 7265 elements of the array.

Commits
-------

0113ac3 Bug #16343 [Router] Too many Routes ?
@jakzal
Copy link
Contributor

jakzal commented Nov 25, 2015

@nicolas-grekas for some reason this PR wasn't closed even though you merged it.

@wouterj
Copy link
Member

wouterj commented Nov 25, 2015

@jakzal that's because it was rebased (on top of 2.3) while merging, so it's not a normal merge commit. In such cases, PRs are closed only when the commit makes it into the default branch (2.8) (because the commit messages includes close #xxxxx). Seems like 2.3 is not yet merged into 2.7/2.8

@fabpot fabpot closed this Nov 25, 2015
@jakzal
Copy link
Contributor

jakzal commented Nov 25, 2015

@wouterj yeah, that's what I thought. Cheers!

This was referenced Nov 30, 2015
This was referenced Dec 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet