find variance of data array using php - php

I want to find variance of the values but i'm not able to find mean correctly. I added explode because while taking array_sum it was showing error that array_sum() expects parameter 1 to be array, string given.
<html><body>
<?php
$ap = '36.222.198.197.166.140';
$counte =0;$sum=0;
$file_handle = fopen("results.csv", "r");
while ( $line_of_text = fgetcsv($file_handle)){
if ($line_of_text[2] == $ap) {
$counte++;
$van = explode(" ",$line_of_text[3]);
$fMean = array_sum($van) / count($van);
print_r ($van);
}
}
fclose($file_handle);
?>
</body></html>
Here is csv format-
time1, time2, mac, 2.4ghz, 5ghz
1485874798, 1485878398, 36.222.198.197.166.140, -73, -72
1485874798, 1485878398, 148.180.15.200.220.114, -69, -65
1485874798, 1485878398, 148.180.15.194.95.70, -74, 0
1485874798, 1485878398, 0.36.108.195.38.227 0, -63
1485874798, 1485878398, 36.222.198.197.171.88, -73, -69
1485874798, 1485878398, 24.100.114.205.236.242, 0, 0
1485874798, 1485878398, 0.36.108.195.34.153 0, 0
1485874798, 1485878398, 148.180.15.200.220.118, -74, -64
1485874798, 1485878398, 0.36.108.195.38.220 0, -74
1485874798, 1485878398, 216.199.200.202.199.48, 0, -67
1485874798, 1485878398, 148.180.15.193.105.60, -62, -66
1485874798, 1485878398, 156.28.18.195.202.230, -74, -74
1485874798, 1485878398, 148.180.15.200.220.126, -73, -71
1485874798, 1485878398, 0.36.108.195.38.219 0, -60
1485874798, 1485878398, 0.36.108.195.38.217, -45, -63
1485874798, 1485878398, 0.36.108.195.38.218, -71, -73
1485874798, 1485878398, 0.36.108.195.38.216, 0, -74
1485874798, 1485878398, 0.36.108.195.33.193, 0, 0
1485874798, 1485878398, 148.180.15.200.220.190, -74, 0
1485874798, 1485878398, 36.222.198.197.166.138, -74, -68
1485874798, 1485878398, 0.36.108.195.33.197, 0, -72
1485874798, 1485878398, 36.222.198.197.171.18, -74, -74
1485874798, 1485878398, 0.36.108.195.33.58, 0, 0
1485874798, 1485878398, 0.36.108.195.33.199, -74, 0
1485874798, 1485878398, 0.36.108.195.31.214, -63, -69
1485874798, 1485878398, 148.180.15.200.220.198, 0, -69
1485874798, 1485878398, 0.36.108.195.31.218 -74, 0
1485874798, 1485878398, 0.36.108.195.35.135, 0, 0
1485874798, 1485878398, 36.222.198.197.171.68, -74, -67
1485874798, 1485878398, 148.180.15.194.97.50, -74, 0
1485874798, 1485878398, 216.199.200.202.200.152, -74, -74
1485874798, 1485878398, 148.180.15.193.134.238, -70, 0
1485874798, 1485878398, 0.36.108.195.35.131, 0, -42
1485874798, 1485878398, 36.222.198.197.170.202, -73, -73
1485874798, 1485878398, 148.180.15.200.220.78, -74, -70
1485874798, 1485878398, 36.222.198.197.170.100, -73, -66
1485874798, 1485878398, 0.36.108.195.30.123, -74, -66

You have inconsistencies in your data:
The first two lines have commas as separators, while the other lines have not.
The second line has an IP address that ends with a dot.
The expression explode(" ",$line_of_text[3]); makes no sense, as $line_of_text[3] is a number, not something with spaces. It also does not make sense to use count on this result, as you want to count rows, not something in one of the fields.
Here is a corrected version:
$ap = '36.222.198.197.166.140';
$file_handle = fopen("results.csv", "r");
while ( $line_of_text = fgetcsv($file_handle)){
if ($line_of_text[2] == $ap) $van[] = $line_of_text[3];
}
fclose($file_handle);
$fMean = array_sum($van) / count($van);
The variance is then calculated like this:
$variance = array_sum(array_map(function ($x) use ($fMean) {
return pow($x - $fMean, 2);
}, $van)) / count($van);

Related

I created and trainend a PHP-FANN but i dont get the desired results or accuraccy

I created a FANN in PHP with the help of some examples and tutorial from
geekgirljoy and based it on the ocr example from the php-fann-repo
I'm trying to create a system which tells me, based on an order number, which type of order this is.
I have crated the training data, trained and tested it, but can't get the result that I expect. I'm now at the point where random changing of parameters isn't helping anymore, and I'm not sure if my assumptions are correct in the beginning.
A little of the training data:
I got 60k lines of spaced splitted binary order numbers
60000 32 1
0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0
0.01
0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 0 0
0.01
0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0
0.01
0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 1 0 0 0
0.01
0 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0
0.07
0 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0
0.07
0 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 0
0.07
0 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0 0 0 0
0.07
The trainend file:
FANN_FLO_2.1
num_layers=3
learning_rate=0.700000
connection_rate=1.000000
network_type=0
learning_momentum=0.000000
training_algorithm=2
train_error_function=1
train_stop_function=0
cascade_output_change_fraction=0.010000
quickprop_decay=-0.000100
quickprop_mu=1.750000
rprop_increase_factor=1.200000
rprop_decrease_factor=0.500000
rprop_delta_min=0.000000
rprop_delta_max=50.000000
rprop_delta_zero=0.100000
cascade_output_stagnation_epochs=12
cascade_candidate_change_fraction=0.010000
cascade_candidate_stagnation_epochs=12
cascade_max_out_epochs=150
cascade_min_out_epochs=50
cascade_max_cand_epochs=150
cascade_min_cand_epochs=50
cascade_num_candidate_groups=2
bit_fail_limit=3.49999994039535522461e-01
cascade_candidate_limit=1.00000000000000000000e+03
cascade_weight_multiplier=4.00000005960464477539e-01
cascade_activation_functions_count=10
cascade_activation_functions=3 5 7 8 10 11 14 15 16 17
cascade_activation_steepnesses_count=4
cascade_activation_steepnesses=2.50000000000000000000e-01 5.00000000000000000000e-01 7.50000000000000000000e-01 1.00000000000000000000e+00
layer_sizes=33 17 2
scale_included=0
neurons (num_inputs, activation_function, activation_steepness)=(0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (0, 0, 0.00000000000000000000e+00) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (33, 5, 5.00000000000000000000e-01) (0, 5, 0.00000000000000000000e+00) (17, 5, 5.00000000000000000000e-01) (0, 5, 0.00000000000000000000e+00)
connections (connected_to_neuron, weight)=(0, -4.61362116038799285889e-02) (1, -7.24165216088294982910e-02) (2, -1.54439583420753479004e-02) (3, 8.89342501759529113770e-02) (4, -1.17050260305404663086e-02) (5, 2.18402743339538574219e-02) (6, 3.76827046275138854980e-02) (7, -4.71979975700378417969e-02) (8, 9.12376716732978820801e-02) (9, -4.86264117062091827393e-02) (10, -8.81998762488365173340e-02) (11, -4.78897392749786376953e-02) (12, 9.77639481425285339355e-02) (13, 2.96645238995552062988e-02) (14, 6.46188631653785705566e-02) (15, 7.25518167018890380859e-03) (16, -9.11594703793525695801e-02) (17, 2.28227004408836364746e-02) (18, 5.24043217301368713379e-02) (19, -4.13042865693569183350e-02) (20, 6.29015043377876281738e-02) (21, 7.06591978669166564941e-02) (22, 5.67197278141975402832e-02) (23, 5.40713146328926086426e-02) (24, 1.12115144729614257812e-02) (25, 1.84408575296401977539e-02) (26, 8.76630619168281555176e-02) (27, -9.43159908056259155273e-02) (28, -2.85221189260482788086e-02) (29, -2.38240733742713928223e-02) (30, -5.08805401623249053955e-02) (31, 2.53416672348976135254e-02) (32, 3.75940650701522827148e-03) (0, 3.36754992604255676270e-02) (1, 1.42759233713150024414e-02) (2, 9.20543894171714782715e-02) (3, -4.44842278957366943359e-02) (4, -4.80413846671581268311e-02) (5, -5.51436059176921844482e-02) (6, -5.32465577125549316406e-02) (7, 3.33221256732940673828e-03) (8, -4.33434806764125823975e-02) (9, -1.13629549741744995117e-03) (10, 1.09615176916122436523e-03) (11, 8.63210633397102355957e-02) (12, -3.65174412727355957031e-02) (13, -9.16486680507659912109e-02) (14, 9.51615795493125915527e-02) (15, 8.63052681088447570801e-02) (16, 6.07556626200675964355e-02) (17, -4.61427047848701477051e-02) (18, 4.92067709565162658691e-02) (19, 3.14148589968681335449e-02) (20, -8.94229784607887268066e-02) (21, 3.27809154987335205078e-03) (22, -5.73736317455768585205e-02) (23, 2.90178731083869934082e-02) (24, -9.05884802341461181641e-03) (25, -5.16896173357963562012e-02) (26, -9.95042547583580017090e-02) (27, 6.71170875430107116699e-02) (28, -2.57015973329544067383e-03) (29, 2.58374139666557312012e-02) (30, -2.91235074400901794434e-02) (31, -6.88946545124053955078e-02) (32, -5.98866716027259826660e-02) (0, -3.70691195130348205566e-02) (1, -1.33788734674453735352e-02) (2, -7.92805850505828857422e-03) (3, 7.78727233409881591797e-03) (4, 3.33745554089546203613e-02) (5, 9.54041555523872375488e-02) (6, 6.44438043236732482910e-02) (7, -6.77617341279983520508e-02) (8, -3.49969416856765747070e-03) (9, 5.07648512721061706543e-02) (10, -4.27917391061782836914e-03) (11, 4.85165417194366455078e-03) (12, 4.59264293313026428223e-02) (13, -1.79739147424697875977e-02) (14, -3.43926995992660522461e-02) (15, 9.97837260365486145020e-02) (16, -6.87671378254890441895e-02) (17, 9.70221534371376037598e-02) (18, -8.96392464637756347656e-02) (19, 3.45109626650810241699e-02) (20, -6.03514760732650756836e-02) (21, 3.93786355853080749512e-02) (22, -7.45478942990303039551e-02) (23, -1.20410919189453125000e-02) (24, 3.98743823170661926270e-02) (25, 9.25691798329353332520e-02) (26, 8.53887572884559631348e-02) (27, -3.42882126569747924805e-02) (28, -3.65543216466903686523e-02) (29, -8.35058987140655517578e-02) (30, 5.82511723041534423828e-03) (31, 2.63765677809715270996e-02) (32, 3.11522185802459716797e-03) (0, 9.78970602154731750488e-02) (1, -6.58361613750457763672e-02) (2, -6.35102093219757080078e-02) (3, 9.33012291789054870605e-02) (4, 9.86076369881629943848e-02) (5, -3.12719494104385375977e-02) (6, -1.01984664797782897949e-02) (7, 4.93725016713142395020e-02) (8, 6.44488856196403503418e-02) (9, 9.46531817317008972168e-02) (10, -4.70107048749923706055e-03) (11, -5.35250306129455566406e-02) (12, -3.97395193576812744141e-02) (13, -4.91733849048614501953e-03) (14, -2.22921743988990783691e-02) (15, -4.27173636853694915771e-02) (16, 5.44340908527374267578e-03) (17, -8.77812206745147705078e-02) (18, -3.06884199380874633789e-03) (19, -5.51779642701148986816e-02) (20, -6.23291134834289550781e-02) (21, 8.48900750279426574707e-02) (22, 8.46964195370674133301e-02) (23, -6.97599276900291442871e-02) (24, 7.02788308262825012207e-02) (25, -4.95917983353137969971e-02) (26, -6.31424784660339355469e-03) (27, 8.67729261517524719238e-02) (28, 5.62333241105079650879e-02) (29, -7.99376815557479858398e-02) (30, -1.01118534803390502930e-02) (31, 5.41303828358650207520e-02) (32, -4.57738414406776428223e-02) (0, 2.63779237866401672363e-02) (1, 4.74315956234931945801e-02) (2, -4.71661984920501708984e-02) (3, 9.51059833168983459473e-02) (4, -6.27668648958206176758e-02) (5, -9.77937132120132446289e-02) (6, 5.95548674464225769043e-02) (7, -6.81136846542358398438e-02) (8, -2.49478220939636230469e-03) (9, -9.39701646566390991211e-02) (10, -7.85320997238159179688e-03) (11, 9.25878807902336120605e-02) (12, -1.62623375654220581055e-02) (13, 4.94294241070747375488e-02) (14, -1.96871906518936157227e-03) (15, -4.04354929924011230469e-03) (16, -5.36394119262695312500e-02) (17, 4.28533181548118591309e-02) (18, 3.36273387074470520020e-02) (19, -6.87493458390235900879e-02) (20, 2.75497362017631530762e-02) (21, 6.38674125075340270996e-02) (22, -9.84705314040184020996e-02) (23, 7.79579356312751770020e-02) (24, -4.24468331038951873779e-02) (25, 8.83023813366889953613e-02) (26, 3.41912582516670227051e-02) (27, -2.23845094442367553711e-02) (28, -2.18094661831855773926e-02) (29, -1.16783604025840759277e-02) (30, 3.18416431546211242676e-02) (31, -9.54315364360809326172e-02) (32, -6.42467588186264038086e-02) (0, 8.46754387021064758301e-02) (1, 9.96744558215141296387e-02) (2, -2.70136222243309020996e-02) (3, 8.68817344307899475098e-02) (4, 5.92293217778205871582e-02) (5, 4.87269461154937744141e-03) (6, -1.56130492687225341797e-02) (7, 6.52591660618782043457e-02) (8, 9.70194861292839050293e-02) (9, -2.30251699686050415039e-02) (10, -5.10031804442405700684e-02) (11, 4.64489087462425231934e-02) (12, 7.50061199069023132324e-02) (13, 4.49532791972160339355e-02) (14, 9.28095057606697082520e-02) (15, 1.78594365715980529785e-02) (16, -2.14193910360336303711e-02) (17, -7.59398490190505981445e-02) (18, -5.45908398926258087158e-02) (19, -5.75519762933254241943e-02) (20, -7.44103714823722839355e-02) (21, -7.66329094767570495605e-02) (22, 1.19209289550781250000e-06) (23, -8.61079841852188110352e-02) (24, 5.75583502650260925293e-02) (25, 7.76166692376136779785e-02) (26, -7.91744887828826904297e-03) (27, -5.41200228035449981689e-02) (28, 9.45831835269927978516e-03) (29, -3.34898382425308227539e-03) (30, -1.83667764067649841309e-02) (31, -5.86624443531036376953e-03) (32, -3.67452949285507202148e-03) (0, 5.46196028590202331543e-02) (1, -1.89845040440559387207e-02) (2, -4.44452166557312011719e-02) (3, -4.05077114701271057129e-02) (4, 6.54024556279182434082e-02) (5, -7.91860669851303100586e-02) (6, -4.34882305562496185303e-02) (7, -5.76227270066738128662e-02) (8, -3.01892384886741638184e-02) (9, -9.70393195748329162598e-02) (10, -8.26166123151779174805e-02) (11, -8.52359682321548461914e-02) (12, 9.57701876759529113770e-02) (13, 3.52428182959556579590e-02) (14, -6.65535777807235717773e-03) (15, -8.01696628332138061523e-02) (16, 8.06519761681556701660e-02) (17, 3.57926562428474426270e-02) (18, -5.45800328254699707031e-02) (19, -9.59809273481369018555e-02) (20, -6.42061531543731689453e-02) (21, -4.06880155205726623535e-02) (22, 6.15774169564247131348e-02) (23, -8.65894779562950134277e-02) (24, 5.13945445418357849121e-02) (25, -9.25426110625267028809e-02) (26, 2.28688344359397888184e-02) (27, -5.19544407725334167480e-02) (28, -1.09093859791755676270e-02) (29, -8.29973965883255004883e-02) (30, 4.43710312247276306152e-02) (31, -5.62897883355617523193e-02) (32, -1.98189914226531982422e-03) (0, 9.99258235096931457520e-02) (1, 3.20249795913696289062e-03) (2, -3.65794524550437927246e-02) (3, -7.92602524161338806152e-02) (4, 5.97142651677131652832e-02) (5, 5.79782575368881225586e-03) (6, -9.44948941469192504883e-03) (7, 6.26749470829963684082e-02) (8, 2.31812149286270141602e-02) (9, 5.31454384326934814453e-03) (10, 5.84451481699943542480e-02) (11, -4.15759757161140441895e-02) (12, 9.86591801047325134277e-02) (13, 7.82754793763160705566e-02) (14, -6.09239935874938964844e-02) (15, 3.44518497586250305176e-02) (16, -7.63045549392700195312e-02) (17, -5.69049231708049774170e-02) (18, 7.02456906437873840332e-02) (19, -1.69925615191459655762e-02) (20, -9.53275039792060852051e-02) (21, 8.36562141776084899902e-02) (22, -6.55980259180068969727e-02) (23, -8.78701135516166687012e-02) (24, 6.52505457401275634766e-03) (25, -1.75524652004241943359e-02) (26, 1.22050195932388305664e-03) (27, 2.35276594758033752441e-02) (28, -7.31814354658126831055e-02) (29, 4.49307188391685485840e-02) (30, -7.84542486071586608887e-02) (31, -7.32556283473968505859e-02) (32, -5.18667846918106079102e-02) (0, -1.50336995720863342285e-02) (1, -5.25158755481243133545e-02) (2, -9.21525135636329650879e-02) (3, 9.07641127705574035645e-02) (4, 3.80346253514289855957e-02) (5, 7.05224350094795227051e-02) (6, 1.39453262090682983398e-02) (7, -5.66508285701274871826e-02) (8, 2.89675816893577575684e-02) (9, 7.23693594336509704590e-02) (10, -5.79916499555110931396e-02) (11, 7.24305957555770874023e-03) (12, -8.85546356439590454102e-02) (13, 7.64601901173591613770e-02) (14, 3.09385135769844055176e-02) (15, -4.54595573246479034424e-02) (16, 4.67058941721916198730e-02) (17, -8.60540568828582763672e-02) (18, -4.07870598137378692627e-02) (19, 3.03620919585227966309e-02) (20, -5.16520775854587554932e-02) (21, -2.86571756005287170410e-02) (22, -6.31128549575805664062e-02) (23, 3.07954624295234680176e-02) (24, 7.25633278489112854004e-02) (25, 6.04147985577583312988e-02) (26, 5.76140210032463073730e-02) (27, 1.74940451979637145996e-02) (28, 8.19605663418769836426e-02) (29, 8.43584015965461730957e-02) (30, 6.56272694468498229980e-02) (31, -3.30731421709060668945e-02) (32, -6.81574791669845581055e-02) (0, 7.34747573733329772949e-02) (1, -4.23090159893035888672e-02) (2, 6.98771551251411437988e-02) (3, 4.39971908926963806152e-02) (4, 7.16363266110420227051e-02) (5, -8.67736712098121643066e-02) (6, -2.70352214574813842773e-02) (7, 4.40056845545768737793e-02) (8, -4.47653122246265411377e-02) (9, 8.02078470587730407715e-02) (10, 5.54510429501533508301e-02) (11, -6.83051198720932006836e-02) (12, 1.11463516950607299805e-02) (13, -9.00085121393203735352e-02) (14, 7.84007683396339416504e-02) (15, 2.50923112034797668457e-02) (16, -3.07955741882324218750e-02) (17, 8.76285880804061889648e-03) (18, 7.34402164816856384277e-02) (19, 4.05472591519355773926e-02) (20, 4.56500127911567687988e-02) (21, 4.23568487167358398438e-03) (22, 1.31105929613113403320e-02) (23, 6.06481730937957763672e-03) (24, -3.81502993404865264893e-02) (25, -6.93953707814216613770e-02) (26, -1.19746178388595581055e-02) (27, -5.37918992340564727783e-02) (28, 9.62318852543830871582e-02) (29, 5.49522563815116882324e-02) (30, -2.19493731856346130371e-02) (31, 6.97066411375999450684e-02) (32, -8.73567685484886169434e-02) (0, -5.20722158253192901611e-02) (1, 1.37038379907608032227e-02) (2, 8.42795446515083312988e-02) (3, -3.88458780944347381592e-02) (4, 8.66686180233955383301e-02) (5, 2.82852128148078918457e-02) (6, 1.63888111710548400879e-02) (7, 6.68764635920524597168e-02) (8, -1.62637382745742797852e-02) (9, 4.80836853384971618652e-02) (10, -2.19771862030029296875e-02) (11, -6.27224892377853393555e-03) (12, 2.64844521880149841309e-02) (13, -9.68848913908004760742e-02) (14, 6.29321858286857604980e-02) (15, -6.47526830434799194336e-02) (16, 7.65553340315818786621e-02) (17, 3.47943603992462158203e-03) (18, 8.08973386883735656738e-02) (19, -1.92089825868606567383e-02) (20, -8.34099799394607543945e-02) (21, -1.30378454923629760742e-02) (22, 4.26407232880592346191e-02) (23, -5.28053492307662963867e-02) (24, 7.49875381588935852051e-02) (25, 8.88488367199897766113e-02) (26, -5.65734580159187316895e-02) (27, 2.99397930502891540527e-02) (28, -3.31005528569221496582e-02) (29, -8.68668183684349060059e-02) (30, 4.25830259919166564941e-02) (31, 1.48272365331649780273e-02) (32, 2.68370136618614196777e-02) (0, 2.68625691533088684082e-02) (1, 7.59813562035560607910e-02) (2, 1.35056376457214355469e-02) (3, -4.48522083461284637451e-02) (4, -7.62983411550521850586e-03) (5, -1.96179077029228210449e-02) (6, 3.88840511441230773926e-02) (7, -5.95461502671241760254e-02) (8, 5.84049001336097717285e-02) (9, -6.73882067203521728516e-02) (10, 6.69383034110069274902e-02) (11, 6.15200176835060119629e-02) (12, 9.55439880490303039551e-02) (13, -9.78143736720085144043e-02) (14, 3.80753502249717712402e-02) (15, -9.76592302322387695312e-04) (16, 8.30829665064811706543e-02) (17, -8.11336338520050048828e-02) (18, 1.56134217977523803711e-02) (19, -2.99548804759979248047e-02) (20, 6.15070834755897521973e-02) (21, 6.28080740571022033691e-02) (22, -5.49673400819301605225e-02) (23, 5.03559187054634094238e-02) (24, -9.37653779983520507812e-02) (25, 7.49724581837654113770e-02) (26, -8.27446356415748596191e-02) (27, -8.06321948766708374023e-02) (28, 1.75554752349853515625e-02) (29, 3.20826098322868347168e-02) (30, 4.62048277258872985840e-02) (31, -5.55819571018218994141e-02) (32, 8.06395709514617919922e-03) (0, -4.02895472943782806396e-02) (1, -4.34167683124542236328e-04) (2, -9.95658785104751586914e-02) (3, 4.00925502181053161621e-02) (4, -6.15501180291175842285e-02) (5, -5.91120272874832153320e-02) (6, -1.50255113840103149414e-03) (7, -2.89383158087730407715e-02) (8, -9.21737253665924072266e-02) (9, -3.99825386703014373779e-02) (10, -3.33943367004394531250e-02) (11, -8.99880975484848022461e-02) (12, 9.80928018689155578613e-02) (13, 6.56290724873542785645e-02) (14, 9.30948629975318908691e-02) (15, -8.30408260226249694824e-02) (16, -1.87574997544288635254e-02) (17, -3.68600189685821533203e-02) (18, 7.84662589430809020996e-02) (19, -5.59494234621524810791e-02) (20, 8.17264616489410400391e-03) (21, 2.88221761584281921387e-02) (22, -4.97148036956787109375e-02) (23, -1.68548971414566040039e-02) (24, 4.60775420069694519043e-02) (25, -3.03469970822334289551e-02) (26, -9.92994233965873718262e-02) (27, -2.18398571014404296875e-02) (28, -8.41421782970428466797e-02) (29, -5.48813790082931518555e-02) (30, 8.62241014838218688965e-02) (31, -2.44317203760147094727e-02) (32, 4.46844622492790222168e-02) (0, 8.66582170128822326660e-02) (1, -8.43391716480255126953e-02) (2, 8.31343457102775573730e-02) (3, -7.24538117647171020508e-02) (4, 1.41582712531089782715e-02) (5, -4.58039753139019012451e-02) (6, -6.46275281906127929688e-02) (7, 7.41757377982139587402e-02) (8, 2.08016857504844665527e-02) (9, -5.46156279742717742920e-02) (10, 7.22685530781745910645e-02) (11, -1.35692507028579711914e-02) (12, -6.15207627415657043457e-02) (13, 8.92277285456657409668e-02) (14, 6.76732584834098815918e-02) (15, 1.61921977996826171875e-03) (16, 6.76939859986305236816e-02) (17, -8.82761701941490173340e-02) (18, -9.02081355452537536621e-02) (19, -3.48383188247680664062e-03) (20, -3.79909761250019073486e-02) (21, -7.06303864717483520508e-03) (22, -5.74062950909137725830e-02) (23, 3.16620245575904846191e-02) (24, -6.36245310306549072266e-03) (25, 2.07538455724716186523e-02) (26, 4.75198552012443542480e-02) (27, 3.87561544775962829590e-02) (28, 6.97793811559677124023e-03) (29, -7.69118666648864746094e-02) (30, -1.65593847632408142090e-02) (31, -6.36383891105651855469e-03) (32, -6.12510368227958679199e-02) (0, -3.34250479936599731445e-02) (1, 2.11823582649230957031e-02) (2, 5.29072359204292297363e-02) (3, 2.07709670066833496094e-02) (4, 5.65548315644264221191e-02) (5, 2.70829871296882629395e-02) (6, -5.84273450076580047607e-02) (7, -9.80608016252517700195e-02) (8, -6.48468732833862304688e-04) (9, 2.80034020543098449707e-02) (10, -5.95815591514110565186e-02) (11, -1.14207416772842407227e-02) (12, -4.32334095239639282227e-03) (13, 4.20376583933830261230e-02) (14, -4.37267534434795379639e-02) (15, 7.40049034357070922852e-03) (16, 5.18295243382453918457e-02) (17, 5.27894124388694763184e-02) (18, 6.94095119833946228027e-02) (19, -5.52335083484649658203e-02) (20, 9.53831151127815246582e-02) (21, 1.07154995203018188477e-03) (22, 3.84040400385856628418e-02) (23, 1.61369666457176208496e-02) (24, -5.14086000621318817139e-02) (25, -2.28398069739341735840e-02) (26, -7.68850892782211303711e-02) (27, -2.83204615116119384766e-02) (28, 6.06008097529411315918e-02) (29, 1.67510733008384704590e-02) (30, 1.04285031557083129883e-02) (31, -7.28242397308349609375e-02) (32, -6.20665699243545532227e-02) (0, -3.66642549633979797363e-02) (1, 4.79467287659645080566e-02) (2, 9.44882556796073913574e-02) (3, 9.04187336564064025879e-02) (4, 8.95193889737129211426e-02) (5, 9.64274480938911437988e-02) (6, -1.02297365665435791016e-02) (7, 1.75227895379066467285e-02) (8, -6.31541088223457336426e-02) (9, 7.83495232462882995605e-02) (10, -8.68005454540252685547e-02) (11, 7.88835510611534118652e-02) (12, -6.53772354125976562500e-02) (13, 2.05999463796615600586e-02) (14, 3.07130888104438781738e-02) (15, 8.74121859669685363770e-02) (16, -9.99053567647933959961e-03) (17, 7.54795745015144348145e-02) (18, 8.27952995896339416504e-02) (19, 9.10810157656669616699e-02) (20, 1.38836055994033813477e-02) (21, -1.06773525476455688477e-03) (22, -6.03275895118713378906e-02) (23, 9.10437926650047302246e-02) (24, 2.20471844077110290527e-02) (25, 1.13519430160522460938e-02) (26, 5.16446009278297424316e-02) (27, -6.12017475068569183350e-02) (28, -7.82195478677749633789e-02) (29, 7.88203552365303039551e-02) (30, -2.32683122158050537109e-02) (31, -1.48838013410568237305e-02) (32, 2.67670825123786926270e-02) (33, -2.87800580263137817383e-02) (34, -2.44650691747665405273e-02) (35, 1.62864699959754943848e-02) (36, -3.23526039719581604004e-02) (37, 6.53051808476448059082e-02) (38, -6.61907345056533813477e-02) (39, 4.49328124523162841797e-03) (40, 4.36547026038169860840e-02) (41, -5.29912821948528289795e-02) (42, -1.66231542825698852539e-02) (43, 7.82774761319160461426e-02) (44, 6.76086619496345520020e-02) (45, -8.59100818634033203125e-02) (46, 6.56896606087684631348e-02) (47, -4.23818789422512054443e-02) (48, 8.95694866776466369629e-02) (49, 4.84849587082862854004e-02)
my training script:
$filenameLoad = dirname(__FILE__) . "/data/order.data";
$filenameSave = dirname(__FILE__) . "/data/ordernumbers_float.net";
$num_input = 32;
$num_output = 1;
$num_layers = 3;
$num_neurons_hidden = ($num_input + $num_output) / 2;
//$num_neurons_hidden = 20;
$desired_error = 0.00001;
$max_epochs = 5000000;
$epochs_between_reports = 10;
$ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
if ($ann) {
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
if (fann_train_on_file($ann, $filenameLoad, $max_epochs, $epochs_between_reports, $desired_error)) {
print('ordernumbers trained' . PHP_EOL);
}
if (fann_save($ann, $filenameSave)) {
print('ordernumbers_float.net saved' . PHP_EOL);
}
fann_destroy($ann);
}
my testing-script:
<?php
//include_once 'Classes/Helper.php';
$train_file = (dirname(__FILE__) . "/data/ordernumbers_float.net");
if (!is_file($train_file)) {
die("The file ordernumbers_float.net has not been created!" . PHP_EOL);
}
//$helper = new Helper();
$ann = fann_create_from_file($train_file);
if ($ann) {
$orderNumber = 108643364;
//$binaryOrderNumber = $helper->getBinaryFromOrdernumber($orderNumber);
$binaryOrderNumber = '00000110011110011100010000100100';
// $input = $helper->getSplittedBinary($binaryOrderNumber);
$input = array("0", "0", "0", "0", "0", "1", "1", "0", "0", "1", "1", "1", "1", "0", "0", "1", "1", "1", "0", "0", "0", "1", "0", "0", "0", "0", "1", "0", "0", "1", "0", "0");
// $inputString = $helper->getSplittetBinaryOutput($input);
$inputString = "0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 0 0 0 0 1 0 0 1 0 0";
$calc_out = fann_run($ann, $input);
printf("ordernumber %s -> %s -> test raw: %f trimmed: %f expected: %f\n", $orderNumber, $inputString, $calc_out[0], floor($calc_out[0] * 100) / 100, 0.01);
fann_destroy($ann);
} else {
die("Invalid file format" . PHP_EOL);
}
Long story short, your dataset is likely too complex for such a small and simple network.When I wrote the OCR example, and I was kind of showing off a little by "compressing" all 94 chars into a single output neuron. It&apos;s not typically done this way and certainly not with complex datasets.Usually, you would want to dedicate an output neuron for each "class" that the network needs to identify.Put simply, its harder for the network to learn to properly increment or decrement the output value by 0.01 on a single neuron (as is the case of my OCR ANN) than to learn to associate a dedicated output neuron / pattern with a specific class.You can find a better example of a more typical classifier implementation in the MNIST subfolder in my repo for the OCR "family" of neural networks: https://github.com/geekgirljoy/OCR_Neural_NetworkMy suggestion is to redesign your ANN.Based on your code your network looks like this:L0: IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIL1: HHHHHHHHHHHHHHHHL2: OWhereas it would probably operate (classify) your data better if you redesigned it like this:First, determine the number of distinct classes types, in the example you gave I saw 0.07 listed so I will assume there are seven different classes of order types.So, the ANN should look like this:L0: IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIL1: A sufficient number of "hidden" neuronsL2: OOOOOOOWhere O1 represents class 1, O2 class 2 etc...Which means that your training data would change to something like this:60000 32 70 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 01 0 0 0 0 0 00 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 0 01 0 0 0 0 0 00 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 01 0 0 0 0 0 00 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1 1 1 0 0 01 0 0 0 0 0 00 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 00 0 0 0 0 0 10 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 00 0 0 0 0 0 10 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 00 0 0 0 0 0 10 0 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0 0 0 00 0 0 0 0 0 1Class Output Examples:Class 1: 1 0 0 0 0 0 0Class 2: 0 1 0 0 0 0 0Class 3: 0 0 1 0 0 0 0Class 4: 0 0 0 1 0 0 0Class 5: 0 0 0 0 1 0 0Class 6: 0 0 0 0 0 1 0Class 7: 0 0 0 0 0 0 1Also, depending on your methodology, you MAY get better results using a harder negative value like -1 instead of 0, like this:60000 32 7-1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 1 1 -1 -1 -1 1 1 -1 -1 1 -11 -1 -1 -1 -1 -1 -1-1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 1 1 -1 -1 -1 1 1 -1 1 -1 -11 -1 -1 -1 -1 -1 -1-1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 1 1 -1 -1 -1 1 1 -1 1 1 -11 -1 -1 -1 -1 -1 -1-1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 1 1 -1 -1 -1 1 1 1 -1 -1 -11 -1 -1 -1 -1 -1 -1-1 -1 -1 1 1 1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 -1 1 -1 1 -1-1 -1 -1 -1 -1 -1 1-1 -1 -1 1 1 1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 -1 1 1 -1 -1-1 -1 -1 -1 -1 -1 1-1 -1 -1 1 1 1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 -1 1 1 1 -1-1 -1 -1 -1 -1 -1 1-1 -1 -1 1 1 1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1-1 -1 -1 -1 -1 -1 1This is because you are using a "symmetric" hidden/output function like FANN_SIGMOID_SYMMETRIC which is a sigmoid and so the relationship between -1 to 0 and from 0 to 1 isn&apos;t linear so you should get better/harder distinctions between classifications and potentially faster training / fewer training epochs by more strongly contrasting the inputs/outputs like this.Anyway, once you have trained the network and run your tests, you simply take the max() output neuron as your answer.Example:// ANN calc inputs and store outputs in the result array$result = fann_run($ann, $input);// Lets say the ANN responds like this:// [-0.9,0.1,-0.2,0.4,0.1,0.5,0.6,0.99,-0.6,0.4]// Let&apos;s also say there are 10 outputs representing that many classes// 0 - 9// [0,1,2,3,4,5,6,7,8,9]//// Find which output contains the highest value (the prediction/classification)$highest = max($result); // $highest now contains the value 0.99// So to convert the highest value to a class we find the key/position in the $result array$class = array_search($highest, $result);var_dump($class);// int(7)Why? Because the 7th key (7th / 8th (depending on how you look at it) is the high value):array(0=>0.9,1=>0.1,2=>-0.2,3=>0.4,4=>0.1,5=>0.5,6=>0.6,7=>0.99,8=>-0.6,0=>0.4);In the case of multiple class types being possible at the same time, you "softmax" instead.Hope this helps! :-)

Convert basic SWF Shapes to SVG

I would export programmatically (in PHP) the content of a SWF file to a SVG format. So, I tried first to export each shapes composing my file to be abble to create the static sprites later.
For that, I use the IO_SWF library to read the content of the swf file.
FillStyles:
[1] solid fill: #d9d2c5(ff)
[2] solid fill: #8e7e66(ff)
[3] solid fill: #b9ae9a(ff)
[4] solid fill: #716044(ff)
LineStyles:
(none)
ShapeRecords:
ChangeStyle: MoveTo: (6.95, -10) FillStyle: 0|2 LineStyle: 0
StraightEdge: MoveTo: (7, -9.95)
StraightEdge: MoveTo: (7.2, -9.65)
StraightEdge: MoveTo: (7.1, -9.45)
StraightEdge: MoveTo: (6.85, -9)
ChangeStyle: MoveTo: (6.85, -9) FillStyle: 0|3 LineStyle: 0
CurvedEdge: MoveTo: Control(6.8, -7.95) Anchor(6.9, -7.15)
StraightEdge: MoveTo: (6.95, -6.25)
StraightEdge: MoveTo: (6.95, -6.15)
StraightEdge: MoveTo: (7, -6.15)
ChangeStyle: MoveTo: (7, -6.15) FillStyle: 0|1 LineStyle: 0
StraightEdge: MoveTo: (6.95, -5.85)
ChangeStyle: MoveTo: (6.95, -5.85) FillStyle: 0|2 LineStyle: 0
StraightEdge: MoveTo: (6.5, -5.2)
StraightEdge: MoveTo: (4.15, -2.3)
StraightEdge: MoveTo: (3.55, -2.15)
ChangeStyle: MoveTo: (3.55, -2.15) FillStyle: 0|4 LineStyle: 0
CurvedEdge: MoveTo: Control(3.7, -3.9) Anchor(5.35, -8.85)
StraightEdge: MoveTo: (6.45, -10.85)
CurvedEdge: MoveTo: Control(6.55, -10.45) Anchor(6.95, -10)
ChangeStyle: MoveTo: (6.95, -10) FillStyle: 2|4 LineStyle: 0
StraightEdge: MoveTo: (6.2, -8.9)
ChangeStyle: MoveTo: (6.2, -8.9) FillStyle: 2|3 LineStyle: 0
StraightEdge: MoveTo: (6.85, -9)
ChangeStyle: MoveTo: (6.2, -8.9) FillStyle: 3|4 LineStyle: 0
StraightEdge: MoveTo: (6.15, -7.85)
StraightEdge: MoveTo: (6.15, -7.7)
StraightEdge: MoveTo: (6.2, -7.55)
StraightEdge: MoveTo: (6.2, -6.9)
StraightEdge: MoveTo: (6.25, -6.75)
ChangeStyle: MoveTo: (6.25, -6.75) FillStyle: 3|1 LineStyle: 0
StraightEdge: MoveTo: (6.35, -6.2)
CurvedEdge: MoveTo: Control(6.4, -6) Anchor(6.7, -5.95)
StraightEdge: MoveTo: (7, -6.15)
ChangeStyle: MoveTo: (4.4, -3.2) FillStyle: 2|4 LineStyle: 0
StraightEdge: MoveTo: (4.15, -2.95)
StraightEdge: MoveTo: (3.55, -2.15)
ChangeStyle: MoveTo: (6.95, -5.85) FillStyle: 2|1 LineStyle: 0
StraightEdge: MoveTo: (6.95, -5.9)
StraightEdge: MoveTo: (6.8, -5.95)
StraightEdge: MoveTo: (6.7, -5.95)
StraightEdge: MoveTo: (6.5, -5.9)
StraightEdge: MoveTo: (6.3, -5.8)
StraightEdge: MoveTo: (4.4, -3.2)
ChangeStyle: MoveTo: (4.4, -3.2) FillStyle: 4|1 LineStyle: 0
StraightEdge: MoveTo: (6.15, -5.85)
StraightEdge: MoveTo: (6.25, -6.75)
ChangeStyle: MoveTo: (0, 0) FillStyle: 0|0 LineStyle: 0
After some research, I understood how to build a svg (composed by path tags) from these data.
ChangeStyle => start a new path => M x,y
StraightEdge => line => L x,y
CurvedEdge => curve => Q cx,cy,ax,ay
And for each path:
FillStyle: {FillStyle0} | {FillStyle1} (0 => no fill style)
The index is related to the FillStyles array
LineStyle: {LineStyle} (0 => line style)
The index is related to the LineStyles array
But this is not the correct way to browse the structure.
Using JPEXS Decompiler to manually export the previous sample shape, I get a perfect traced SVG.
Here is a comparative:
My result vs what is expected
My resulting svg:
<path fill="rgba(185, 174, 154, 1)" fill-rule="evenodd" stroke="none" d="M 6.95 -10 L 7 -9.95 L 7.2 -9.65 L 7.1 -9.45 L 6.85 -9 L 6.95 -10" />
<path fill="rgba(217, 210, 197, 1)" fill-rule="evenodd" stroke="none" d="M 6.85 -9 Q 6.8 -7.95 6.9 -7.15 L 6.95 -6.25 L 6.95 -6.15 L 7 -6.15 L 6.85 -9" />
<path fill="rgba(142, 126, 102, 1)" fill-rule="evenodd" stroke="none" d="M 7 -6.15 L 6.95 -5.85 L 7 -6.15" />
<path fill="rgba(113, 96, 68, 1)" fill-rule="evenodd" stroke="none" d="M 6.95 -5.85 L 6.5 -5.2 L 4.15 -2.3 L 3.55 -2.15 L 6.95 -5.85" />
<path fill="rgba(142, 126, 102, 1)" fill-rule="evenodd" stroke="none" d="M 3.55 -2.15 Q 3.7 -3.9 5.35 -8.85 L 6.45 -10.85 Q 6.55 -10.45 6.95 -10 L 3.55 -2.15" />
<path fill="rgba(142, 126, 102, 1)" fill-rule="evenodd" stroke="none" d="M 6.95 -10 L 6.2 -8.9 L 6.95 -10" />
<path fill="rgba(185, 174, 154, 1)" fill-rule="evenodd" stroke="none" d="M 6.2 -8.9 L 6.85 -9 L 6.2 -8.9" />
<path fill="rgba(185, 174, 154, 1)" fill-rule="evenodd" stroke="none" d="M 6.2 -8.9 L 6.15 -7.85 L 6.15 -7.7 L 6.2 -7.55 L 6.2 -6.9 L 6.25 -6.75 L 6.2 -8.9" />
<path fill="rgba(142, 126, 102, 1)" fill-rule="evenodd" stroke="none" d="M 6.25 -6.75 L 6.35 -6.2 Q 6.4 -6 6.7 -5.95 L 7 -6.15 L 6.25 -6.75" />
<path fill="rgba(142, 126, 102, 1)" fill-rule="evenodd" stroke="none" d="M 4.4 -3.2 L 4.15 -2.95 L 3.55 -2.15 L 4.4 -3.2" />
<path fill="rgba(113, 96, 68, 1)" fill-rule="evenodd" stroke="none" d="M 6.95 -5.85 L 6.95 -5.9 L 6.8 -5.95 L 6.7 -5.95 L 6.5 -5.9 L 6.3 -5.8 L 4.4 -3.2 L 6.95 -5.85" />
And the JPEXS result:
<path d="M7.0 -6.15 L6.95 -5.85 6.95 -5.9 6.8 -5.95 6.7 -5.95 6.5 -5.9 6.3 -5.8 4.4 -3.2 6.15 -5.85 6.25 -6.75 6.35 -6.2 Q6.4 -6.0 6.7 -5.95 L7.0 -6.15" fill="#d9d2c5" fill-rule="evenodd" stroke="none" />
<path d="M6.95 -10.0 L7.0 -9.95 7.2 -9.65 7.1 -9.45 6.85 -9.0 6.2 -8.9 6.95 -10.0 M6.95 -5.85 L6.5 -5.2 4.15 -2.3 3.55 -2.15 4.15 -2.95 4.4 -3.2 6.3 -5.8 6.5 -5.9 6.7 -5.95 6.8 -5.95 6.95 -5.9 6.95 -5.85" fill="#8e7e66" fill-rule="evenodd" stroke="none" />
<path d="M6.85 -9.0 Q6.8 -7.95 6.9 -7.15 L6.95 -6.25 6.95 -6.15 7.0 -6.15 6.7 -5.95 Q6.4 -6.0 6.35 -6.2 L6.25 -6.75 6.2 -6.9 6.2 -7.55 6.15 -7.7 6.15 -7.85 6.2 -8.9 6.85 -9.0" fill="#b9ae9a" fill-rule="evenodd" stroke="none" />
<path d="M3.55 -2.15 Q3.7 -3.9 5.35 -8.85 L6.45 -10.85 Q6.55 -10.45 6.95 -10.0 L6.2 -8.9 6.15 -7.85 6.15 -7.7 6.2 -7.55 6.2 -6.9 6.25 -6.75 6.15 -5.85 4.4 -3.2 4.15 -2.95 3.55 -2.15" fill="#716044" fill-rule="evenodd" stroke="none" />
All in all, how could I obtain the same well formed SVG from my data structure? I'm pretty sure there's a subtility with FillStyle0 and FillStyle1, but which?
Thanks for your help.

PHP uses rdkafka to produce messages that hang for 100ms

when i use rdkafka produce message in php, The program will hang 100ms
My code reference is this website https://switchcaseblog.wordpress.com/2017/01/20/how-to-get-php-and-kafka-to-play-nicely-and-not-do-it-slowly/
php version: PHP 7.0.13
rdkafka version:
version => 3.0.5
build date => Dec 23 2017 20:38:03
librdkafka version (runtime) => 0.11.3
produce config:
'request.required.acks' => 0,
'message.timeout.ms' => 300,
'queue.buffering.max.ms' => 1,
'message.max.bytes' => 3000000,
'socket.keepalive.enable' => true
so i strace the php process, The following code:
21:05:07.395746 fcntl(4, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=1}) = 0
21:05:07.395799 fcntl(4, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=1}) = 0
21:05:07.395828 munmap(0x7f9036659000, 1106) = 0
21:05:07.395853 close(5) = 0
21:05:07.396263 futex(0x7f902be5e580, FUTEX_WAKE_PRIVATE, 2147483647) = 0
21:05:07.396484 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
21:05:07.396531 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f900641a000
21:05:07.396577 mprotect(0x7f900641a000, 4096, PROT_NONE) = 0
21:05:07.396614 clone(child_stack=0x7f9006e19e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f9006e1a9d0, tls=0x7f9006e1a700, child_tidptr=0x7f9006e1a9d0) = 22018
21:05:07.396696 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0
21:05:07.396764 pipe([5, 6]) = 0
21:05:07.396833 fcntl(5, F_GETFL) = 0 (flags O_RDONLY)
21:05:07.396858 fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
21:05:07.396880 fcntl(6, F_GETFL) = 0x1 (flags O_WRONLY)
21:05:07.396902 fcntl(6, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
21:05:07.396926 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f9005a19000
21:05:07.396962 mprotect(0x7f9005a19000, 4096, PROT_NONE) = 0
21:05:07.397013 clone(child_stack=0x7f9006418e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f90064199d0, tls=0x7f9006419700, child_tidptr=0x7f90064199d0) = 22019
21:05:07.397107 rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0
21:05:07.397137 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
21:05:07.397191 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
21:05:07.397219 pipe([7, 8]) = 0
21:05:07.397245 fcntl(7, F_GETFL) = 0 (flags O_RDONLY)
21:05:07.397268 fcntl(7, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
21:05:07.397290 fcntl(8, F_GETFL) = 0x1 (flags O_WRONLY)
21:05:07.397311 fcntl(8, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
21:05:07.397335 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f9005018000
21:05:07.397372 mprotect(0x7f9005018000, 4096, PROT_NONE) = 0
21:05:07.397421 clone(child_stack=0x7f9005a17e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f9005a189d0, tls=0x7f9005a18700, child_tidptr=0x7f9005a189d0) = 22020
21:05:07.397469 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
21:05:07.397507 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
21:05:07.397534 pipe([9, 10]) = 0
21:05:07.397560 fcntl(9, F_GETFL) = 0 (flags O_RDONLY)
21:05:07.397582 fcntl(9, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
21:05:07.397604 fcntl(10, F_GETFL) = 0x1 (flags O_WRONLY)
21:05:07.397626 fcntl(10, F_SETFL, O_WRONLY|O_NONBLOCK) = 0
21:05:07.397650 mmap(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f9004616000
21:05:07.397687 mprotect(0x7f9004616000, 4096, PROT_NONE) = 0
21:05:07.397733 clone(child_stack=0x7f9005015e90, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f90050169d0, tls=0x7f9005016700, child_tidptr=0x7f90050169d0) = 22021
21:05:07.397781 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
21:05:07.398147 write(1, "\350\200\227\346\227\2666\346\257\253\347\247\222", 13耗时6毫秒) = 13
21:05:07.398203 write(1, "\n", 1
) = 1
21:05:07.398318 close(2) = 0
21:05:07.398347 close(1) = 0
21:05:07.398372 munmap(0x7f903665a000, 4096) = 0
21:05:07.398433 close(0) = 0
21:05:07.398456 munmap(0x7f903665b000, 4096) = 0
21:05:07.398490 futex(0x212e19c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, {1514034307, 399482000}, ffffffff) = -1 ETIMEDOUT (Connection timed out)
21:05:07.399575 futex(0x212e170, FUTEX_WAKE_PRIVATE, 1) = 0
21:05:07.399602 futex(0x212e19c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 3, {1514034307, 400596000}, ffffffff) = -1 ETIMEDOUT (Connection timed out)
21:05:07.400684 futex(0x212e170, FUTEX_WAKE_PRIVATE, 1) = 0
21:05:07.400710 futex(0x212e19c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 5, {1514034307, 401704000}, ffffffff) = 0
21:05:07.401209 futex(0x212e170, FUTEX_WAKE_PRIVATE, 1) = 0
21:05:07.401268 futex(0x212e25c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x212e258, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
21:05:07.401316 futex(0x7f9006e1a9d0, FUTEX_WAIT, 22018, NULL) = 0
21:05:07.502855 munmap(0x7f8ff75ff000, 10489856) = 0
21:05:07.503046 fcntl(4, F_SETLK, {type=F_UNLCK, whence=SEEK_SET, start=0, len=0}) = 0
21:05:07.503295 munmap(0x7f9006e1b000, 67108864) = 0
21:05:07.503417 close(4) = 0
21:05:07.503530 munmap(0x7f902be63000, 2182736) = 0
21:05:07.503580 munmap(0x7f902bbac000, 2844152) = 0
21:05:07.503662 munmap(0x7f902c078000, 2186600) = 0
21:05:07.503776 munmap(0x7f902c954000, 2129096) = 0
21:05:07.503811 munmap(0x7f902c740000, 2176864) = 0
21:05:07.503842 munmap(0x7f902c503000, 2343352) = 0
21:05:07.503891 munmap(0x7f902c28e000, 2574912) = 0
21:05:07.503939 munmap(0x3e5ea00000, 2109528) = 0
21:05:07.503988 munmap(0x7f902cb5c000, 2111520) = 0
21:05:07.504095 munmap(0x7f902cd60000, 2108464) = 0
21:05:07.504151 munmap(0x7f902cf63000, 2129280) = 0
21:05:07.504242 munmap(0x7f902d7ec000, 2155960) = 0
21:05:07.504277 munmap(0x7f902d581000, 2533392) = 0
21:05:07.504332 munmap(0x7f902d9fb000, 2163080) = 0
21:05:07.504421 munmap(0x7f900ae1b000, 2113976) = 0
21:05:07.504479 munmap(0x7f900b020000, 2113944) = 0
21:05:07.504524 munmap(0x7f900b225000, 2126432) = 0
21:05:07.504560 munmap(0x7f900b42d000, 2113976) = 0
21:05:07.504601 munmap(0x7f900b9a6000, 2117960) = 0
21:05:07.504630 munmap(0x7f900b632000, 3618944) = 0
21:05:07.504668 futex(0x7f902dedc040, FUTEX_WAKE_PRIVATE, 2147483647) = 0
21:05:07.504712 munmap(0x7f902dc0c000, 2956168) = 0
21:05:07.504857 munmap(0x7f902e8b1000, 2514584) = 0
21:05:07.504918 munmap(0x7f902e58d000, 3293152) = 0
21:05:07.504966 munmap(0x7f902e0eb000, 4856016) = 0
21:05:07.505086 munmap(0x7f902dede000, 2150272) = 0
21:05:07.505151 munmap(0x7f902ed31000, 2144104) = 0
21:05:07.505194 munmap(0x7f902eb17000, 2202200) = 0
strace -c php scritp.php
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
95.15 0.001000 59 17 3 futex
4.85 0.000051 0 742 615 open
0.00 0.000000 0 97 read
0.00 0.000000 0 9 write
0.00 0.000000 0 129 close
0.00 0.000000 0 77 49 stat
0.00 0.000000 0 148 fstat
0.00 0.000000 0 57 1 lstat
0.00 0.000000 0 2 poll
0.00 0.000000 0 8 3 lseek
0.00 0.000000 0 259 1 mmap
0.00 0.000000 0 127 mprotect
Futex takes about 100ms, how to solve it
who can help me? thanks
谁能帮忙解答下,哈哈

How to simplify array into only unique values in Python

Because of array depth issues in PHP, receiving this array from Python becomes truncated with an ellipsis ("..."). I'd like to process the array in Python before returning back to php.
Clarification: I need to maintain the inner sets [135, 121, 81]. These are R, G, B values and I'm tying to group sets that occur more than once. Values in sets need to maintain [1, 2, 3] sequence, NOT [1,2,3,4,5,6,7,8] as some answers have suggested below.
How would you simplify this 3D numpy.ndarray to a collection of unique RGB triples?
Here is how the array is printed by Python:
[[[135 121 81]
[135 121 81]
[135 121 81]
...,
[135 121 81]
[135 121 81]
[135 121 81]]
[[135 121 81]
[135 121 81]
[135 121 81]
...,
[135 121 81]
[135 121 81]
[135 121 81]]
[[ 67 68 29]
[135 121 81]
[ 67 68 29]
...,
[135 121 81]
[135 121 81]
[135 121 81]]
...,
[[200 170 19]
[200 170 19]
[200 170 19]
...,
[ 67 68 29]
[ 67 68 29]
[ 67 68 29]]
[[200 170 19]
[200 170 19]
[200 170 19]
...,
[116 146 15]
[116 146 15]
[116 146 15]]
[[200 170 19]
[200 170 19]
[200 170 19]
...,
[116 146 15]
[116 146 15]
[116 146 15]]]
Here is the code that I have attempted:
def uniquify(arr)
keys = []
for c in arr:
if not c in keys:
keys[c] = 1
else:
keys[c] += 1
return keys
result = uniquify(items)
Based on the representation of your "array", it looks like you're working with a numpy.ndarray. This becomes quite a simple problem if that is the case -- You can transform to a 1-D iterable simple by using the .flat attribute. To make it unique, you can just use a set:
set(array.flat)
This will give you a set, but you could easily get a list from it:
list(set(array.flat))
Here's how it works:
>>> array = np.zeros((10,12,42,53))
>>> list(set(array.flat))
[0.0]
As a side note, there's also np.unique which will give you the unique elements of your array as well.
>>> array = np.zeros((10,12),dtype=int)
>>> print array
[[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0]]
>>> np.unique(array)
array([0])
>>> array[0,5] = 1
>>> array[4,10] = 42
>>> np.unique(array)
array([ 0, 1, 42])
I think I finally got this one figured out:
from itertools import product
items = set(tuple(a[itr+(slice(None),)]) for itr in product(*[range(x) for x in a.shape[:-1]]))
print items
Seems to work. Phew!
How this works -- the pieces that you want to keep as triplets are accessed as:
array[X,Y,:]
So, we just need to loop over all of the combinations of X and Y. That is exactly what itertools.product is good for. We can get the valid X and Y in an arbitrary number of dimensions:
[range(x) for x in array.shape[:-1]]
So we pass that to product:
indices_generator = product(*[range(x) for x in array.shape[:-1]])
Now we have something that will generate the first to indices -- We just need to construct a tuple to pass to __getitem__ that numpy will interpret as (X,Y,:) -- That's easy, we're already getting (X,Y) from indices_generator -- We just need to tack on an emtpy slice:
all_items = ( array[idx+(slice(None),)] for idx in indices_generator )
Now we can loop over all_items looking for the unique ones with a set:
unique_items = set(tuple(item) for item in all_items)
Now turn this back into a list, or a numpy array or whatever you want for the purposes of passing it back to PHP.
Look at the recipes in the itertools documentation. There are flatten and unique_everseen functions that do exactly what you want.
So, you can copy and paste them. Or you can just pip install more-itertools so you just import them. Now, you can flatten the 3D array to 2D, and uniquify the 2D array with unique_everseen…
Except for one problem. The elements of your 2D array are lists, which are not hashable, so you have to convert them to something hashable. But that's easy:
def uniquify(arr3d):
return unique_everseen(flatten(arr3d), tuple)
That's it.
And if you look at the implementations of those functions while you're pasting them, they're pretty simple. The only real trick here is using a set to hold the values seen so far: sets only hold one copy of each unique element (and can determine whether an element is already in the set very quickly).
In fact, if you don't need to preserve the ordering, it's even simpler:
def uniquify(arr3d):
return set(tuple(x) for x in flatten(arr3d))
As a test, I copied your string and turned it into an actual Python list display, then did this:
inarray = [[[135, 121, 81],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81]],
[[135, 121, 81],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81]],
[[67, 68, 29],
[135, 121, 81],
[67, 68, 29],
[135, 121, 81],
[135, 121, 81],
[135, 121, 81]],
[[200, 170, 19],
[200, 170, 19],
[200, 170, 19],
[67, 68, 29],
[67, 68, 29],
[67, 68, 29]],
[[200, 170, 19],
[200, 170, 19],
[200, 170, 19],
[116, 146, 15],
[116, 146, 15],
[116, 146, 15]],
[[200, 170, 19],
[200, 170, 19],
[200, 170, 19],
[116, 146, 15],
[116, 146, 15],
[116, 146, 15]]]
for val in uniquify(inarray):
print(val)
The output was:
[135, 121, 81]
[67, 68, 29]
[200, 170, 19]
[116, 146, 15]
Is that what you wanted?
If you want it as a list of lists, that's just:
array2d = list(uniquify(array3d))
If you're used a simple set instead of unique_everseen, these will be tuples instead of lists, so if you need a list of lists:
array2d = [list(val) for val in uniquify(array3d)]
Assuming the python list looks like [[[1,2,3], [4,5,6]], [[7,8,9]]] (that is, a list of lists of integers
mylist = [[[1,2,3], [4,5,6]], [[7,8,9]]]
items = set()
for sublist in mylist:
for subsublist in sublist:
for item in subsublist:
items.add(item)
If you then specifically need a list, you can just cast it as so: items = list(items)
A set is a datatype that is similar to a list, but doesn't contain duplicates.
A side-effect of the set datatype is the insertion order isn't preserved - if this is important to you you'll need something like:
mylist = [[[1,2,3], [4,5,6]], [[7,8,9]]]
items = []
for sublist in mylist:
for subsublist in sublist:
for item in subsublist:
if not item in items:
items.add(item)
Edit: based on your edit, you probably want this:
mylist = [[[1,2,3], [4,5,6]], [[7,8,9], [1,2,3]]]
items = []
for sublist in mylist:
for item in sublist:
if not item in items:
items.append(item)
# items = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
itertools is your friend here:
>>> import itertools
>>> array = [1,1,1,2,2,2,3,3,3,4,5,6,6,6]
>>> [x[0] for x in itertools.groupby(array)]
[1, 2, 3, 4, 5, 6]
For example:
array = [[[135,121,81],
[135,121,81],
[135,121,81],
[135,121,81],
[135,121,81],
[135,121,81]],
[[135,121,81],
[135,121,81],
[135,121,81],
[135,121,81],
[135,121,81],
[135,121,81]],
[[67,68,29],
[135,121,81],
[67,68,29],
[135,121,81],
[135,121,81],
[135,121,81]]]
import itertools
new_array = list()
for inner in array:
new_inner = [x[0] for x in itertools.groupby(inner)]
new_array.append(new_inner)
Produces:
[ [ [135, 121, 81] ],
[ [135, 121, 81] ],
[ [67, 68, 29],
[135, 121, 81],
[67, 68, 29],
[135, 121, 81] ] ]
Not quite unique, but you can sort inner to get only unique.

file_get_contents fails on debian (lenny) server

Not sure if it's because it's out of life, but it has been running a website and working until very recently (1 week) - the server hasn't been updated, so am not sure what happened to break the script.
Here's a test script that I've been running (and fails) on the debian server:
<?php
$url = "http://www.andyloughran.co.uk/test.html";
echo $url."\n";
$test = file_get_contents($url);
echo $test;
That should normally return 'ndy test' or something similar.
However, on the debian box it's just timing out.
I've checked and I can wget the file:
<?php
exec('wget http://www.andyloughran.co.uk/test.html');
so am not sure what is it in file_get_contents that isn't working.
I've checked and allow_fopen_url is set to On.
I could do with advice not just on fixing this problem, but working out how to debug the php in order to be able to identify the problem myself in the future.
Curl is not really an option at the moment, as I'm more interested in working out why it's stopped working, rather than an alternative.
Thanks!
Here's the strace error:
open("/dev/urandom", O_RDONLY) = 3
read(3, "\202\231\320\206"..., 4) = 4
close(3) = 0
open("/dev/urandom", O_RDONLY) = 3
read(3, "cdO\37"..., 4) = 4
close(3) = 0
brk(0x9133000) = 0x9133000
open("http_test.php", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=187, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7837000
read(3, "<?php\n\nini_set('display_errors', "..., 4096) = 187
_llseek(3, 0, [0], SEEK_SET) = 0
time(NULL) = 1348748612
fstat64(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
fstat64(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7836000
_llseek(0, 0, 0xbfae579c, SEEK_CUR) = -1 ESPIPE (Illegal seek)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7835000
_llseek(1, 0, 0xbfae579c, SEEK_CUR) = -1 ESPIPE (Illegal seek)
fstat64(2, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
_llseek(2, 0, 0xbfae579c, SEEK_CUR) = -1 ESPIPE (Illegal seek)
getcwd("/root"..., 4096) = 6
time(NULL) = 1348748612
lstat64("/root", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/root/http_test.php", {st_mode=S_IFREG|0644, st_size=187, ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfae3798) = -1 ENOTTY (Inappropriate ioctl for device)
read(3, "<?php\n\nini_set('display_errors', "..., 8192) = 187
read(3, ""..., 4096) = 0
read(3, ""..., 8192) = 0
close(3) = 0
munmap(0xb7837000, 4096) = 0
write(1, "http://www.andyloughran.co.uk/tes"..., 40http://www.andyloughran.co.uk/test.html
) = 40
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
close(3) = 0
socket(PF_NETLINK, SOCK_RAW, 0) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=28901, groups=00000000}, [12]) = 0
time(NULL) = 1348748612
sendto(3, "\24\0\0\0\26\0\1\3DEdP\0\0\0\0\0\0\0\0"..., 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"0\0\0\0\24\0\2\0DEdP\345p\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1\10"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 156
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"#\0\0\0\24\0\2\0DEdP\345p\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 64
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0DEdP\345p\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
close(3) = 0
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=95, ...}) = 0
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=141, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7837000
read(3, "127.0.0.1 localhost.localdomain l"..., 4096) = 141
read(3, ""..., 4096) = 0
close(3) = 0
munmap(0xb7837000, 4096) = 0
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=141, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7837000
read(3, "127.0.0.1 localhost.localdomain l"..., 4096) = 141
read(3, ""..., 4096) = 0
close(3) = 0
munmap(0xb7837000, 4096) = 0
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=32850, ...}) = 0
mmap2(NULL, 32850, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7820000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libnss_dns.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220\v\0\0004\0\0\0x"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=17880, ...}) = 0
mmap2(NULL, 20616, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xca5000
mmap2(0xca9000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3) = 0xca9000
close(3) = 0
munmap(0xb7820000, 32850) = 0
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=95, ...}) = 0
gettimeofday({1348748612, 441933}, NULL) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 28) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
gettimeofday({1348748612, 442194}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "2k\1\0\0\1\0\0\0\0\0\0\3www\fandyloughran\2co\2"..., 40, MSG_NOSIGNAL) = 40
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [102]) = 0
recvfrom(3, "2k\201\200\0\1\0\0\0\1\0\0\3www\fandyloughran\2co\2"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 102
close(3) = 0
gettimeofday({1348748612, 755352}, NULL) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 28) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
gettimeofday({1348748612, 755589}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\312-\1\0\0\1\0\0\0\0\0\0\3www\fandyloughran\2co\2"..., 56, MSG_NOSIGNAL) = 56
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [121]) = 0
recvfrom(3, "\312-\201\203\0\1\0\0\0\1\0\0\3www\fandyloughran\2co\2"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 121
close(3) = 0
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=95, ...}) = 0
gettimeofday({1348748613, 222946}, NULL) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 28) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
gettimeofday({1348748613, 223253}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\254Q\1\0\0\1\0\0\0\0\0\0\3www\fandyloughran\2co\2"..., 40, MSG_NOSIGNAL) = 40
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [56]) = 0
recvfrom(3, "\254Q\201\200\0\1\0\1\0\0\0\0\3www\fandyloughran\2co\2"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 56
close(3) = 0
gettimeofday({1348748613, 400717}, NULL) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("85.119.82.243")}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=3, revents=POLLOUT}])
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl64(3, F_SETFL, O_RDWR) = 0
send(3, "GET /test.html HTTP/1.0\r\n"..., 25, MSG_DONTWAIT) = 25
send(3, "Host: www.andyloughran.co.uk\r\n"..., 30, MSG_DONTWAIT) = 30
send(3, "User-Agent: PHP\r\n"..., 17, MSG_DONTWAIT) = 17
send(3, "\r\n"..., 2, MSG_DONTWAIT) = 2
poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 60000^C <unfinished ...>
allow_url_fopen = On in php.ini
Check your DNS, ping www.andyloughran.co.uk
Throw the server out of the nearest window.
I had the same problemn a while ago. It was a DNS problem. Restarting the Webserver helped.
file_get_contents won't work with a URI.
Just try this:
$Stuff = file_get_contents($_SERVER['DOCUMENT_ROOT']."path/filename");
file_get_contents will be happy to "see" a local and accessible path. It will present you the file contents as a kind of "function-thank-you" ;)

Categories