These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Yapeal PHP API library (2.0)

Author
Dragonaire
Here there be Dragons
#41 - 2014-08-03 20:33:26 UTC
Kolb - I would assume from the all default_time_zone warnings that you are using Ubuntu and they still haven't figured out like all the other distros how to set the time zone correctly in php.ini Sad. You probably need to fix that yourself and I'll look at adding something into Yapeal to also take care of it for it's needs. I thought I already had it setting it but must not have made it in like I thought.

On the segfault looks like you're simple running out of memory with even less than 1000 row inserts so you might want to make sure your memory_limit is high enough in php.ini. 32MB should be enough but my current setting is 128MB here on my test machine. I've not done any really memory profiling on Yapeal this time but I've used best practices to keep it as small as possible with the limit of course being the size of the Eve API XML itself. One reason I limit individual upserts to under 1001 row is to try keeping memory use lower plus work around some limits with typical MySQL setups.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Kolb
Fancy Fox Enterprises
#42 - 2014-08-03 20:51:27 UTC
Dragonaire wrote:
Kolb - I would assume from the all default_time_zone warnings that you are using Ubuntu and they still haven't figured out like all the other distros how to set the time zone correctly in php.ini Sad. You probably need to fix that yourself and I'll look at adding something into Yapeal to also take care of it for it's needs. I thought I already had it setting it but must not have made it in like I thought.

On the segfault looks like you're simple running out of memory with even less than 1000 row inserts so you might want to make sure your memory_limit is high enough in php.ini. 32MB should be enough but my current setting is 128MB here on my test machine. I've not done any really memory profiling on Yapeal this time but I've used best practices to keep it as small as possible with the limit of course being the size of the Eve API XML itself. One reason I limit individual upserts to under 1001 row is to try keeping memory use lower plus work around some limits with typical MySQL setups.


I sorted all the defaults timezones out, but in my .ini I already had

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M

I doubled it to 256 but it's still

[2014-08-03 20:48:50] yapeal.DEBUG: Started filesystem retrieve for corp/WalletTransactions [] []
[2014-08-03 20:48:50] yapeal.DEBUG: Started XSD validating [] []
[2014-08-03 20:48:50] yapeal.INFO: Have 838 row(s) to upsert into corpWalletTransactions table [] []
Segmentation fault (core dumped)
Kolb
Fancy Fox Enterprises
#43 - 2014-08-03 20:54:57 UTC
Just to test it out I even tried setting it to no limit -1 same problem.
Dragonaire
Here there be Dragons
#44 - 2014-08-04 16:09:40 UTC  |  Edited by: Dragonaire
So did a little more research on seg-faults in PHP and seem what's going on is you're hitting a bug in PHP itself or one of it's extensions. Based on the log messages just before it happens I'd say there are one of 2 possible things that can be causing it in the EveApiToolsTrait.php file.

  • The preg_replace() on line 91
  • PDO prepare() or execute() on lines 97-99


Since the message the preg_replace() is creating is never shown it the most likely cause but there is a small chance that it doesn't get written to the log before PHP seg-faults and aborts the background OS I/O process. Easy way to find out is to just comment out lines 91-93 where it's creating and trying to log the message and see if it stops seg-faulting.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Kolb
Fancy Fox Enterprises
#45 - 2014-08-04 19:54:43 UTC
Dragonaire wrote:
So did a little more research on seg-faults in PHP and seem what's going on is you're hitting a bug in PHP itself or one of it's extensions. Based on the log messages just before it happens I'd say there are one of 2 possible things that can be causing it in the EveApiToolsTrait.php file.

  • The preg_replace() on line 91
  • PDO prepare() or execute() on lines 97-99


Since the message the preg_replace() is creating is never shown it the most likely cause but there is a small chance that it doesn't get written to the log before PHP seg-faults and aborts the background OS I/O process. Easy way to find out is to just comment out lines 91-93 where it's creating and trying to log the message and see if it stops seg-faulting.


Commenting out those lines did stop the seg-fault; would you like a list of my modules to help narrow down the source of the problem for future reference?

Dragonaire
Here there be Dragons
#46 - 2014-08-04 23:31:20 UTC
No it's the preg_replace() causing the problem I'm sure. The default setting they use for pcre.backtrack_limit is only 100k chars and the string was trying to process I'm guessing is closer to 200k. you can try uncommenting them and increase the setting to say 1M and see if it works but I'll probably still push out another fix that just replaces it instead. I like the RegExp because it was a single line but easy enough to use something else.

https://github.com/Dragonrun1/yapeal/issues/31

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Legedric Striker
State War Academy
Caldari State
#47 - 2014-08-05 18:41:11 UTC  |  Edited by: Legedric Striker
Edit: Forget it, somehow my host had still php 5.3.x activated...

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Legedric Striker
State War Academy
Caldari State
#48 - 2014-08-06 08:09:34 UTC
So after about two weeks of work I just finished most parts of my project using Yapeal!

You may visit the very first version here:
http://www.eve-skillplan.net/

Of course I will add and tweak some features during the next days but it is at least in state to make the site public from now on.
Thanks again for this amazing library, Dragonaire!

A seperate thread for this project will follow soon.

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Dragonaire
Here there be Dragons
#49 - 2014-08-06 20:50:04 UTC
CCP is adding new char and corp Blueprints APIs which can be seen on test server now. I've adding them to Yapeal but set isActive=0 in utilEveApi for now until they get deployed to Tranquility.

Legedric Striker - Great to see you get it out for people to take a look and glad to hear you found Yapeal useful. I've took a quick look but not had time to actually try it but I'll try to get around to that soon.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Legedric Striker
State War Academy
Caldari State
#50 - 2014-08-07 05:55:42 UTC  |  Edited by: Legedric Striker
I think I somehow ran into a problem here.

My cronjob is running the "autoMagic" every single minute now which is being completed within just a couple of seconds (< 3 seconds).

However, it does not get fresh XML from the API for at least some characters (I didn't check all).

For example, when I am calling the API for this character manually to get the character sheet I get something like this:
Quote:

*eveapi version="2"*
*currentTime*2014-08-07 05:42:32*/currentTime*
*result*
*characterID*90750214*/characterID*
*name*Legedric Striker*/name*
*DoB*2011-05-16 15:19:00*/DoB*
.
.
.


When I look into the yapeal.log for the most recent entry of this character I see the following:
Quote:

[2014-08-07 05:28:02] yapeal.DEBUG: Checking if cache expired on table charCharacterSheet for ownerID = 90750214 [] []
[2014-08-07 05:28:02] yapeal.DEBUG: SELECT "expires" FROM "d01b51d3"."yap_utilCachedUntil" WHERE "apiName" = 'CharacterSheet' AND "sectionName" = 'Char' AND "ownerID" = 90750214 [] []
[2014-08-07 05:28:02] yapeal.DEBUG: Expired UtilCachedUntil record found [] []
[2014-08-07 05:28:02] yapeal.INFO: select get_lock('d1ad71e33090aff96dd6883077144a5d',5) [] []
[2014-08-07 05:28:02] yapeal.DEBUG: Started filesystem retrieve for char/CharacterSheet [] []
[2014-08-07 05:28:02] yapeal.DEBUG: Started XSD validating [] []
[2014-08-07 05:28:02] yapeal.DEBUG: characterID => 90750214 [] []
[2014-08-07 05:28:02] yapeal.DEBUG: name => Legedric Striker [] []
[2014-08-07 05:28:02] yapeal.DEBUG: DoB => 2011-05-16 15:19:00 [] []
.
.
.


The expires datetime in the database for this record is 2014-08-06 08:15:03 (EVE time), so something like 21 hours in the past!
The cache file (d1ad71e33090aff96dd6883077144a5d) has the following content in contrary to the top xml which I pulled from teh API manually:
Quote:

*eveapi version="2"*
*currentTime*2014-08-06 07:15:03*/currentTime*
*result*
*characterID*90750214*/characterID*
*name*Legedric Striker*/name*
*DoB*2011-05-16 15:19:00*/DoB*
.
.
.


Of course all the other data like accountBalance etc. are outdated...
It seems like even though the cachedUntil record is expired for several hours now, Yapeal doesn't pull fresh data from the API but uses the cached file over and over again instead.

I checked the CHMOD settings and it is set to 777 for all cache folders within yapeal (777 just for testing of course!). The XML itself however do have CHMOD 644, so is it possible that yapeal cannot update the cache files properly? But why are they 644 when I set 777 recursively from the top "cache" folder?

/Edit:
So I reset all CHMOD settings to 764 for the cache folder and all files within - so the old existing files are available for updates now. But new files will still be created with 644 (of course) and so they are impossible to be updated by yapeal... Sad

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Tiberius Zol
Moira.
#51 - 2014-08-07 08:21:10 UTC
Is there a way to update the DB after i downloaded the new updates via git? Without dropping existing tables?

Mr. Tibbers on twitter: @Mr_Tibbers

Mr. Tibbers Blog: www.eve-versum.de

Kolb
Fancy Fox Enterprises
#52 - 2014-08-07 12:11:04 UTC
Legedric Striker wrote:

Of course all the other data like accountBalance etc. are outdated...
It seems like even though the cachedUntil record is expired for several hours now, Yapeal doesn't pull fresh data from the API but uses the cached file over and over again instead.

I checked the CHMOD settings and it is set to 777 for all cache folders within yapeal (777 just for testing of course!). The XML itself however do have CHMOD 644, so is it possible that yapeal cannot update the cache files properly? But why are they 644 when I set 777 recursively from the top "cache" folder?

/Edit:
So I reset all CHMOD settings to 764 for the cache folder and all files within - so the old existing files are available for updates now. But new files will still be created with 644 (of course) and so they are impossible to be updated by yapeal... Sad


have you tried recursivly chowning the directory to www-data?
Legedric Striker
State War Academy
Caldari State
#53 - 2014-08-07 13:54:26 UTC  |  Edited by: Legedric Striker
Well, I think this may be the problem for me, my hoster is running PHP 5.3 usually on this server and to activate PHP 5.5 I have to use a CGI handler in my htaccess file.

As a result, PHP is not being run as www-data but as the main FTP user so chown is set to this user for all folders recursively.

Unfortunately this is something I cannot change...

But as PHP is running using this main FTP user and all the cache XML files belong to this user it shouldn't be problem at all. the problem seems to be that the newly generated cache files have CHMOD 644 and so they cannot be change by yapeal afterwards.

It is very strange however that yapeal can create new files without any problems but it seems like it cannot update the content of those new fiules once they are created. So the "last changed date" is changing but not the content itself as you can see above.

Other parts of my project (log4net for example) have no trouble manipulating files.

Perhaps I will try to write a second cronjob that iterates through all cache files having the wrong CHMOD and set it to 775 via PHP and that will doe the trick Blink

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Legedric Striker
State War Academy
Caldari State
#54 - 2014-08-07 18:06:51 UTC  |  Edited by: Legedric Striker
After some investigation I think it may not be a permission problem.

At least as far as I understand the corresponding Yapeal parts it should delete the cache file once it is expired.
Quote:

$cachePath =
$this->getNormalizedCachePath($data->getEveApiSectionName());
$this->checkUsableCachePath($cachePath);
$cacheFile =
$cachePath . $data->getEveApiName() . $data->getHash() . '.xml';
$this->checkUsableCacheFile($cacheFile);
$this->prepareConnection($cacheFile);
$result = $this->readXmlData($cacheFile);
$this->__destruct();
if ($this->isExpired($result)) {
$mess = sprintf('Deleting expired cache file %1$s', $cacheFile);
$this->getLogger()
->debug($mess);
@unlink($cacheFile);
return $this;
}


Log output:
Quote:
[2014-08-07 17:55:04] yapeal.DEBUG: Checking if cache expired on table charCharacterSheet for ownerID = 90750214 [] []
[2014-08-07 17:55:04] yapeal.DEBUG: SELECT "expires" FROM "d01b51d3"."yap_utilCachedUntil" WHERE "apiName" = 'CharacterSheet' AND "sectionName" = 'Char' AND "ownerID" = 90750214 [] []
[2014-08-07 17:55:04] yapeal.DEBUG: Expired UtilCachedUntil record found [] []
[2014-08-07 17:55:04] yapeal.INFO: select get_lock('d1ad71e33090aff96dd6883077144a5d',5) [] []
[2014-08-07 17:55:04] yapeal.DEBUG: Started filesystem retrieve for char/CharacterSheet [] []
[2014-08-07 17:55:04] yapeal.DEBUG: Started XSD validating [] []


But nowhere in my log I can see "Deleting expired cache file"... so it always uses the old and way outdated cache file over and over again Sad

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Dragonaire
Here there be Dragons
#55 - 2014-08-07 18:45:24 UTC  |  Edited by: Dragonaire
Legedric Striker - Could be that some of my changes to have Yapeal do a better job of reusing the FS cache aren't right yet I'll look at it again.

Edit: Make sure you are using up to date version after I fixed issue #19. I improved the handling of cached XML files. The cache files being 0644 is fine actually since that means the owner has read/write access and as long as the user Yapeal is run as is the same user it should be fine.

Just something else I picked up on when re-reading your post is your talking about CGI and Yapeal.
Quote:
and to activate PHP 5.5 I have to use a CGI handler in my htaccess file.

Just to make it clear Yapeal should be ran with the CLI version of PHP not the one made to work with the web server. Not that anything in Yapeal really requires this but because of how CGI is setup on most shared hosts you can run into problems. Not sure that is what's going on here but I'd find the path to use the CLI version of PHP and see if it doesn't help. In most cases its something like /usr/bin/php but could be different if they are installing multiple version to allow for 5.3 and 5.4 etc.

Also it's better not to have Yapeal within you web server path as then there is always a chance that someone can try crafting a URL and access it directly as a web page. Main possible problem here is they would probably get to see the log messages that normal end up in the log file or are visible when running Yapeal directly from the command line. Shouldn't really see anything like passwords etc but still best that it's not an option.

You might also set your logging level to 250(NOTICE) and see if some more logging messages show up for you. If you want you can go all the way down to 100(Debug) here during testing and it might pick something extra up as well but generally not needed.

\lib\Xml\FileCacheRetriever::isExpired() is where it decided if the XML is expired or not. Welcome to look at it and see if you see any fault in the logic but I'm not finding any.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Legedric Striker
State War Academy
Caldari State
#56 - 2014-08-07 20:14:12 UTC
Well, as you can see I already set my log level to 100 to see the debug messages and there is no message for deleting old cache files in there and I am using a Yapeal master branch version from 2 or 3 days ago so the issue#19 fix is already included.

I also found the IsExpired function and it seems to operate just right, although I didn't have the time to debug all the way through it just now.

As I am not my own host I have no possibility to run Yapeal anywhere else than within my web server path but I will protect the complete vendor folder path and subfolders etc. using htaccess as soon as I got a stable version of Yapeal running.

I will continue with the debugging of the specific parts of Yapeal tomorrow and post here whatever I may find or not find while doing so Blink

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Legedric Striker
State War Academy
Caldari State
#57 - 2014-08-07 21:14:31 UTC  |  Edited by: Legedric Striker
Ok so I just did some debugging for the isExpired function in FileCacheRetriever.php

It is ALWAYS returning false for me as my cache files are (as said) several hours old.
The reason is line 278:

Quote:

if (($current + 300) <= $now) {
return false;


$current (is taken from the cached XML file - which is way too old) is like shown above from yesterday in some cases and so it is always sure that "whatever time from yesterday +300 seconds" is lower than "now".

So I changed it to:

Quote:

if (($current + 300) >= $now) {
return false;


In addition I also changed the following lines:
Quote:
if ($until >= $now) {
return true;
}


into:
Quote:

if ($until < $now) {
return true;
}


I am somewhat confused as the function is called isExpired I expect it to be TRUE if the cachedUntil time is in the past, so cachedUntil <= now and not like its in the original lines... same goes for the 5 minutes minimum cache which is also obviously turned around.

I somwhere saw a function called isNOTexpired which is operating the other way round (not for cache files though) so I think you may have mixed up the purpose of the isExpired function here with its actual code Blink

After I uploaded the changes to my webspace the cached files are being updated again and the API is working as intended again!

Cheers and it's time for some sleep now! Big smile

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Dragonaire
Here there be Dragons
#58 - 2014-08-08 04:21:54 UTC
Legedric Striker - Ok updated it should work correctly now. The problem I was having is when I first started writing the method I had $current and $now flipped in what they were set to and when I changed them to what they are now I didn't get them fully flipped in my mind as well so ended up with things backwards but thanks for figuring it out. I took a little different approach on minimum time which is more what I had in mind originally. It won't run into the problem you were having but still sets a minimum cache time like I was wanting.

Finds camping stations from the inside much easier. Designer of Yapeal for the Eve API. Check out the Yapeal PHP API Library thread.

Legedric Striker
State War Academy
Caldari State
#59 - 2014-08-08 05:11:18 UTC
Great, I just updated to the most recent build of your master branch Smile

EVE-Skillplan.net - Plan your pilot skill training online on PC, Mac, tablet or smartphone!

Tiberius Zol
Moira.
#60 - 2014-08-08 13:23:00 UTC
Please.... change the databasescript and delete the drop table stuff.. i have deleted my whole database with months of work now because installing the new branch and update the databasestuff with yc Database:Init or create something like yc Database:Update

and my provider doesn't give me a backup -.-

Mr. Tibbers on twitter: @Mr_Tibbers

Mr. Tibbers Blog: www.eve-versum.de