I'm getting this sudden error, and I can't figure our whats going on. I just reloaded the page and it started happening.
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 5526419083341876096 bytes)
For some reason, this piece of code is triggering the error:
array('#hash-algos' => implode(', ', hash_algos())))
The only thing in the error logs is a repeat of the above error message.
The piece of code is a part of Drupal, and I'm running the latest version. I just edited a CSS file, reloaded, only to be confronted with that error.
I'm running PHP 7 on WampServer on Windows 10 x64
hash_algos() on it's own returns the following:
array(46) {
[0]=>
string(3) "md2"
[1]=>
string(3) "md4"
[2]=>
string(3) "md5"
[3]=>
string(4) "sha1"
[4]=>
string(6) "sha224"
[5]=>
string(6) "sha256"
[6]=>
string(6) "sha384"
[7]=>
string(6) "sha512"
[8]=>
string(9) "ripemd128"
[9]=>
string(9) "ripemd160"
[10]=>
string(9) "ripemd256"
[11]=>
string(9) "ripemd320"
[12]=>
string(9) "whirlpool"
[13]=>
string(10) "tiger128,3"
[14]=>
string(10) "tiger160,3"
[15]=>
string(10) "tiger192,3"
[16]=>
string(10) "tiger128,4"
[17]=>
string(10) "tiger160,4"
[18]=>
string(10) "tiger192,4"
[19]=>
string(6) "snefru"
[20]=>
string(9) "snefru256"
[21]=>
string(4) "gost"
[22]=>
string(11) "gost-crypto"
[23]=>
string(7) "adler32"
[24]=>
string(5) "crc32"
[25]=>
string(6) "crc32b"
[26]=>
string(6) "fnv132"
[27]=>
string(7) "fnv1a32"
[28]=>
string(6) "fnv164"
[29]=>
string(7) "fnv1a64"
[30]=>
string(5) "joaat"
[31]=>
string(10) "haval128,3"
[32]=>
string(10) "haval160,3"
[33]=>
string(10) "haval192,3"
[34]=>
string(10) "haval224,3"
[35]=>
string(10) "haval256,3"
[36]=>
string(10) "haval128,4"
[37]=>
string(10) "haval160,4"
[38]=>
string(10) "haval192,4"
[39]=>
string(10) "haval224,4"
[40]=>
string(10) "haval256,4"
[41]=>
string(10) "haval128,5"
[42]=>
string(10) "haval160,5"
[43]=>
string(10) "haval192,5"
[44]=>
string(10) "haval224,5"
[45]=>
string(10) "haval256,5"
}
OK, well. This is strange, I restarted the WampServers, and it still happened. But I restarted my computer, and now it has stopped. Maybe something else is causing this? I did install a couple extra PHP extensions, and also a version of memcached for Windows. Perhaps something like that was causing it? I'm not sure, I'm not hugely familiar with how PHP works internally.
Related
I'm trying to get an array of function names for extensions Refletion, mysqlnd, xmlreader, Phar, pdo_mysql, xsl using standard get_extension_funcs() but it returns false instead of array of names. This is strange as it returns names for any other module. For example, it works for xmlwriter. But it does not work for xmlreader.
I have PHP 8.0.2. What am I doing wrong? Sample code:
$ php -r "var_dump(get_extension_funcs('xmlreader'));"
bool(false)
$ php -r "var_dump(get_extension_funcs('xmlwriter'));"
array(42) {
[0]=>
string(18) "xmlwriter_open_uri"
[1]=>
string(21) "xmlwriter_open_memory"
[2]=>
string(20) "xmlwriter_set_indent"
[3]=>
string(27) "xmlwriter_set_indent_string"
[4]=>
string(23) "xmlwriter_start_comment"
[5]=>
string(21) "xmlwriter_end_comment"
[6]=>
string(25) "xmlwriter_start_attribute"
[7]=>
string(23) "xmlwriter_end_attribute"
[8]=>
string(25) "xmlwriter_write_attribute"
[9]=>
string(28) "xmlwriter_start_attribute_ns"
[10]=>
string(28) "xmlwriter_write_attribute_ns"
[11]=>
string(23) "xmlwriter_start_element"
[12]=>
string(21) "xmlwriter_end_element"
[13]=>
string(26) "xmlwriter_full_end_element"
[14]=>
string(26) "xmlwriter_start_element_ns"
[15]=>
string(23) "xmlwriter_write_element"
[16]=>
string(26) "xmlwriter_write_element_ns"
[17]=>
string(18) "xmlwriter_start_pi"
[18]=>
string(16) "xmlwriter_end_pi"
[19]=>
string(18) "xmlwriter_write_pi"
[20]=>
string(21) "xmlwriter_start_cdata"
[21]=>
string(19) "xmlwriter_end_cdata"
[22]=>
string(21) "xmlwriter_write_cdata"
[23]=>
string(14) "xmlwriter_text"
[24]=>
string(19) "xmlwriter_write_raw"
[25]=>
string(24) "xmlwriter_start_document"
[26]=>
string(22) "xmlwriter_end_document"
[27]=>
string(23) "xmlwriter_write_comment"
[28]=>
string(19) "xmlwriter_start_dtd"
[29]=>
string(17) "xmlwriter_end_dtd"
[30]=>
string(19) "xmlwriter_write_dtd"
[31]=>
string(27) "xmlwriter_start_dtd_element"
[32]=>
string(25) "xmlwriter_end_dtd_element"
[33]=>
string(27) "xmlwriter_write_dtd_element"
[34]=>
string(27) "xmlwriter_start_dtd_attlist"
[35]=>
string(25) "xmlwriter_end_dtd_attlist"
[36]=>
string(27) "xmlwriter_write_dtd_attlist"
[37]=>
string(26) "xmlwriter_start_dtd_entity"
[38]=>
string(24) "xmlwriter_end_dtd_entity"
[39]=>
string(26) "xmlwriter_write_dtd_entity"
[40]=>
string(23) "xmlwriter_output_memory"
[41]=>
string(15) "xmlwriter_flush"
}
Even if I assume that some extensions does not have any functions, there are some extensions which SHOULD have functions, eg. mysqlnd should have mysqli_fetch_all() as noted in official docs.
Also, I assure that all those extensions are loaded and working fine.
$ php -r "var_dump(extension_loaded('mysqlnd'));"
bool(true)
$ php -r "var_dump(get_extension_funcs('mysqlnd'));"
bool(false)
FALSE is returned if there are no functions in that extension.
For example;
<?php
get_extension_funcs("xmlreader");
Returns;
false
because that extension defines the XMLReader class but not functions.
According JB comment
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I've read every single question on StackOverflow on how to parse JSON with PHP but none of them are working with the JSON I have.
array(2) { ["status"]=> bool(true) ["currency"]=> array(30) { [0]=>
array(10) { ["currency"]=> string(7) "EUR/AUD" ["value"]=> string(6)
"1.4925" ["change"]=> string(7) "-0.0076" ["change_percent"]=>
string(8) "-0.50663" ["ask"]=> string(6) "1.4926" ["bid"]=> string(6)
"1.4923" ["daily_lowest"]=> string(6) "1.4873" ["daily_highest"]=>
string(6) "1.5016" ["date"]=> string(19) "2017-08-16 09:46:11"
["type"]=> string(8) "original" } [1]=> array(10) { ["currency"]=>
string(7) "EUR/CAD" ["value"]=> string(5) "1.494" ["change"]=>
string(7) "-0.0032" ["change_percent"]=> string(8) "-0.21373"
["ask"]=> string(5) "1.494" ["bid"]=> string(6) "1.4939"
["daily_lowest"]=> string(5) "1.489" ["daily_highest"]=> string(6)
"1.4986" ["date"]=> string(19) "2017-08-16 09:46:11" ["type"]=>
string(8) "original" } [2]=> array(10) { ["currency"]=> string(7)
"EUR/CHF" ["value"]=> string(6) "1.1434" ["change"]=> string(6)
"0.0024" ["change_percent"]=> string(7) "0.21034" ["ask"]=> string(6)
"1.1435" ["bid"]=> string(6) "1.1434" ["daily_lowest"]=> string(6)
"1.1402" ["daily_highest"]=> string(6) "1.1444" ["date"]=> string(19)
"2017-08-16 09:46:11" ["type"]=> string(8) "original" } [3]=>
array(10) { ["currency"]=> string(7) "EUR/GBP" ["value"]=> string(6)
"0.9099" ["change"]=> string(7) "-0.0019" ["change_percent"]=>
string(8) "-0.20838" ["ask"]=> string(4) "0.91" ["bid"]=> string(6)
"0.9099" ["daily_lowest"]=> string(6) "0.9083" ["daily_highest"]=>
string(6) "0.9144" ["date"]=> string(19) "2017-08-16 09:46:11"
["type"]=> string(8) "original" } [4]=> array(10) { ["currency"]=>
string(7) "EUR/ILS" ["type"]=> string(9) "converted" ["date"]=>
string(19) "2017-08-16 09:46:11" ["value"]=> string(7) "4.24323"
["change"]=> string(3) "0.0" ["change_percent"]=> string(3) "0.0"
["ask"]=> string(3) "0.0" ["bid"]=> string(3) "0.0" ["daily_lowest"]=>
string(3) "0.0" ["daily_highest"]=> string(3) "0.0" } [5]=> array(10)
{ ["currency"]=> string(7) "EUR/JPY" ["value"]=> string(8) "130.1145"
["change"]=> string(6) "0.2425" ["change_percent"]=> string(7)
"0.18672" ["ask"]=> string(7) "130.122" ["bid"]=> string(7) "130.107"
["daily_lowest"]=> string(7) "129.613" ["daily_highest"]=> string(7)
"130.405" ["date"]=> string(19) "2017-08-16 09:46:11" ["type"]=>
string(8) "original" } [6]=> array(10) { ["currency"]=> string(7)
"EUR/NZD" ["value"]=> string(6) "1.6182" ["change"]=> string(7)
"-0.0036" ["change_percent"]=> string(8) "-0.22198" ["ask"]=>
string(6) "1.6186" ["bid"]=> string(6) "1.6178" ["daily_lowest"]=>
string(6) "1.6138" ["daily_highest"]=> string(6) "1.6247" ["date"]=>
string(19) "2017-08-16 09:46:11" ["type"]=> string(8) "original" }
[7]=> array(10).............
I'm trying to output the value of each ["currency"] ["bid"] with this code:
foreach($result['currency'][0]['bid'] as $item) {
print $item['currency'][0]['bid'];
}
And tried 100 other variations, still getting errors like:
Warning: Illegal string offset 'currency' in getData.php on line 27
Warning: Illegal string offset 'value' in getData.php on line 27
Warning: Invalid argument supplied for foreach() in getData.php on line 27
Maybe there are online parser websites that can help with that? How do I solve this?
It seems to me like it should be.
foreach($result['currency']as $item) {
print $item['value'];
}
Because each currency is 0,1,2 and so on.
And in the item 0,1,2 there is the "value".
After I use array_unique on an array, when I var_dump the array, it still has the same content, with duplicates:
array(21) {
[0]=> string(10) "tricou_CRS"
[1]=> string(10) "tricou_CRM"
[2]=> string(11) "tricou_CRXL"
[3]=> string(10) "tricou_CBM"
[4]=> string(10) "tricou_CBL"
[5]=> string(10) "tricou_CWS"
[6]=> string(11) "tricou_CWXL"
[7]=> string(10) "tricou_CRS"
[8]=> string(10) "tricou_CRM"
[9]=> string(11) "tricou_CRXL"
[10]=> string(10) "tricou_CBM"
[11]=> string(10) "tricou_CBL"
[12]=> string(10) "tricou_CWS"
[13]=> string(11) "tricou_CWXL"
[14]=> string(10) "tricou_CRS"
[15]=> string(10) "tricou_CRM"
[16]=> string(11) "tricou_CRXL"
[17]=> string(10) "tricou_CBM"
[18]=> string(10) "tricou_CBL"
[19]=> string(10) "tricou_CWS"
[20]=> string(11) "tricou_CWXL" }
Which obviously has some duplicates. Now, there's not much code that could help, really, because it's just array_unique($myarr);var_dump($myarr);.
So, what am I missing there? Shouldn't array_unique remove the duplicates? Both the type and the content is the same in many of the array's positions.
$uniquearr = array_unique($myarr);
var_dump($uniquearr);
Always read docs first
http://www.php.net/array_unique
array_unique
Return Values
Returns the filtered array.
Here is a sample var_dump. Now, how do I know how to construct a foreach from it to load any particular word or fragment in to an array?
object(stdClass)#1 (2)
{
["noun"]=>
object(stdClass)#2 (1)
{
["syn"]=> array(24)
{
[0]=> string(12) "domestic dog"
[1]=> string(16) "Canis familiaris"
[2]=> string(5) "frump"
[3]=> string(3) "cad"
[4]=> string(7) "bounder"
[5]=> string(10) "blackguard"
[6]=> string(5) "hound"
[7]=> string(4) "heel"
[8]=> string(5) "frank"
[9]=> string(11) "frankfurter"
[10]=> string(6) "hotdog"
[11]=> string(7) "hot dog"
[12]=> string(6) "wiener"
[13]=> string(11) "wienerwurst"
[14]=> string(6) "weenie"
[15]=> string(4) "pawl"
[16]=> string(6) "detent"
[17]=> string(5) "click"
[18]=> string(7) "andiron"
[19]=> string(7) "firedog"
[20]=> string(8) "dog-iron"
[21]=> string(8) "blighter"
[22]=> string(5) "canid"
[23]=> string(6) "canine"
[24]=> string(5) "catch"
}
}
}
Before we can decipher it, we have to format it.
Tobias Kun's answer shows a very good way to format the var_dump output so you can read it.
object(stdClass)#1 (2)
{
["noun"]=>
object(stdClass)#2 (1)
{
["syn"]=> array(24)
{
[0]=> string(12) "domestic dog"
[1]=> string(16) "Canis familiaris"
[2]=> string(5) "frump"
[3]=> string(3) "cad"
[4]=> string(7) "bounder"
[5]=> string(10) "blackguard"
[6]=> string(5) "hound"
[7]=> string(4) "heel"
[8]=> string(5) "frank"
[9]=> string(11) "frankfurter"
[10]=> string(6) "hotdog"
[11]=> string(7) "hot dog"
[12]=> string(6) "wiener"
[13]=> string(11) "wienerwurst"
[14]=> string(6) "weenie"
[15]=> string(4) "pawl"
[16]=> string(6) "detent"
[17]=> string(5) "click"
[18]=> string(7) "andiron"
[19]=> string(7) "firedog"
[20]=> string(8) "dog-iron"
[21]=> string(8) "blighter"
[22]=> string(5) "canid"
[23]=> string(6) "canine"
[24]=> string(5) "catch"
}
}
}
You have a stdClass object with a property called ,"noun". noun is an abject with a property called "syn", which is an array of strings.
Suppose we call the object $object. Then we can access the array like:
echo $object->noun->syn[23];
which gives us canine. So a loop might look like:
foreach($data->noun->syn as $value) {
echo $value . "<br>\n";
}
First of all you should really increase the quality of your questions. The code is not formatted at all.
If you use echo "<pre>" . print_r($your_data_object_or_array,1) . "</pre>" your data will be formatted fine.
If i understand you right this should help you:
foreach($data['noun']['syn'] as $value) {
//with this you loop through all your words in "syn" e.g. domestic, "Canis familiaris etc."
echo $value . "<br>";
}
//Ouput:
domestic
Canis familiaris
frump
cad
etc ...
i am working on a custom Google Analytics implementation making use of direct utm.gif requests.
The problem:
Google Analytics doesnt track any data. Maybe because sth. is wrong with the parameters?
Thank's for helping
Sample: trackPage parameters
array(16) {
[0]=>
string(53) "http://www.google-analytics.com/__utm.gif?utmwv=4.5.7"
[1]=>
string(14) "utmn=474288553"
[2]=>
string(34) "utmhn=labs.domain.de%2Fphp%2Fga%2F"
[3]=>
string(16) "utmcs=ISO-8859-1"
[4]=>
string(11) "utmul=de-de"
[5]=>
string(7) "utmsr=-"
[6]=>
string(7) "utmsc=-"
[7]=>
string(7) "utmje=-"
[8]=>
string(7) "utmfl=-"
[9]=>
string(6) "utmr=-"
[10]=>
string(70) "utme=8%28userstatus%2Amyvariable%299%28nofan%2Amyvalue%2911%281%2A1%29"
[11]=>
string(14) "utmdt=Homepage"
[12]=>
string(16) "utmhid=441842675"
[13]=>
string(12) "utmp=home%2F"
[14]=>
string(17) "utmac=UA-123456-1"
[15]=>
string(191) "utmcc=__utma%253D186215409.1789216404.1265552708.1288611723.1288619999.26%253B%252B__utmz%253D186215409.1288619999.1.1.utmcsr%3D%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29%253B"
}
Sample: trackEvent parameters
array(15) {
[0]=>
string(53) "http://www.google-analytics.com/__utm.gif?utmwv=4.5.7"
[1]=>
string(14) "utmn=240340321"
[2]=>
string(34) "utmhn=labs.domain.de%2Fphp%2Fga%2F"
[3]=>
string(10) "utmt=event"
[4]=>
string(16) "utmcs=ISO-8859-1"
[5]=>
string(11) "utmul=de-de"
[6]=>
string(7) "utmsr=-"
[7]=>
string(7) "utmsc=-"
[8]=>
string(7) "utmje=-"
[9]=>
string(7) "utmfl=-"
[10]=>
string(6) "utmr=-"
[11]=>
string(116) "utme=5%28permission%2Apublish_stream%2Agranted%29%281%298%28userstatus%2Amyvariable%299%28%2Amyvalue%2911%281%2A1%29"
[12]=>
string(16) "utmhid=364249414"
[13]=>
string(17) "utmac=UA-123456-1"
[14]=>
string(191) "utmcc=__utma%253D186215409.1789216404.1265552708.1288611723.1288620331.26%253B%252B__utmz%253D186215409.1288620331.1.1.utmcsr%3D%28direct%29%7Cutmccn%3D%28direct%29%7Cutmcmd%3D%28none%29%253B"
}
This one is generated with another lib and it's working. But i can't find my fault?
array(14) {
[0]=>
string(53) "http://www.google-analytics.com/__utm.gif?utmwv=4.5.7"
[1]=>
string(15) "utmn=8893029624"
[2]=>
string(18) "utmhn=labs.domain.de%2Fphp%2Fga%2F"
[3]=>
string(7) "utmcs=-"
[4]=>
string(7) "utmsr=-"
[5]=>
string(7) "utmsc=-"
[6]=>
string(11) "utmul=de-de"
[7]=>
string(7) "utmje=-"
[8]=>
string(7) "utmfl=-"
[9]=>
string(14) "utmdt=Homepage"
[10]=>
string(6) "utmr=-"
[11]=>
string(10) "utmp=/home"
[12]=>
string(17) "utmac=UA-123456-1"
[13]=>
string(199) "utmcc=__utma%3D155417661.238248693.1267644354.1279870281.1279921084.8%3B%2B__utmz%3D155417661.1279824753.5.6.utmccn=(organic)%7Cutmcsr=google%7Cutmctr=facebook%20goole%20analytics%7Cutmcmd=organic%3B"
}