Firmware: A-410 [01 Apr. 2014] | A-400 [12 Mar. 2014] | C-300 [13 Feb. 2014] | A-300 [24 Feb. 2014] | C-200 [11 July 2013] | A-200/A-210 [11 July 2013] | Popbox V8 [3 Dec 2013]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Thread Closed 
PHP Script restart issue
02-16-2009, 06:22 AM (This post was last modified: 02-16-2009 06:55 AM by cmgrant.)
Post: #1
PHP Script restart issue
Wondering if anyone can help me with this or at least explain it.

I am running PHP scripts through the interface

Code:
<a href="http://127.0.0.1:8088/stream/file=/opt/sybhttpd/localhost.drives/HARD_DISK/Video/DMJ/scan.php?">

It seems if these scripts take more then a certain amount of time to execute the PCH browser restarts it. As a result I am getting multiple entries in my database because of when the PCH seems to be choosing its restart. It also seems like if it has to restart it too many times it throws an error when infact the script just takes a long time to run. ini_get('max_execution_time') returns a value of 3600, and set time seems to have no effect. Can anyone shed some light on it?

cmgrant

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
02-16-2009, 08:35 AM (This post was last modified: 02-16-2009 08:38 AM by journey4712.)
Post: #2
RE: PHP Script restart issue
howabout set_time_limit() ?

There is also ini_set('max_input_time', xxxxxx); iirc opening documents with fopen/etc will add up untill they get to max_input_time, so multiple internet requests could trigger this one.

If i remember right there are 3 or 4 things that effect this but i cant find my reference.

journey4712
Find all posts by this user
02-16-2009, 02:47 PM
Post: #3
RE: PHP Script restart issue
I have tried both set_time_limit() and ini_set('max_input_time', xxxxxx); with no luck. It seems to me the initial 3600 (this is 1 hour right?) should be fine. It only gets about 30 seconds of runtime before it gets reset and re-invoked. Is there possibly some other setting that would cause this? There are multiple instances of getting stuff on the net and opening files.

cmgrant

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
02-16-2009, 02:54 PM
Post: #4
RE: PHP Script restart issue
Think this was an issue for the Music Album Browser as well... might be worth checking that thread.

http://www.networkedmediatank.com/showth...nd+browser
Find all posts by this user
02-16-2009, 02:56 PM (This post was last modified: 02-16-2009 02:58 PM by Delphy.)
Post: #5
RE: PHP Script restart issue
Try ini_set('max_execution_time', xxxx);

The /mnt/syb8634/server/php.ini has it set to 30 (hence why the 30 second runtime). So I guess if all else fails you can modify it there and restart the server to see what happens.

How are you getting things from the net? file_get_contents() or something else?

(On a side note it would be great if we could add in PHP modules or recompile PHP from scratch ... maybe I'll work on that next)

My NMT apps / themes
Find all posts by this user
02-16-2009, 06:14 PM (This post was last modified: 02-16-2009 06:17 PM by cmgrant.)
Post: #6
RE: PHP Script restart issue
(02-16-2009 02:54 PM)dolph Wrote:  Think this was an issue for the Music Album Browser as well... might be worth checking that thread.

http://www.networkedmediatank.com/showth...nd+browser

Thanks I'll check it out.
(02-16-2009 02:56 PM)Delphy Wrote:  Try ini_set('max_execution_time', xxxx);

The /mnt/syb8634/server/php.ini has it set to 30 (hence why the 30 second runtime). So I guess if all else fails you can modify it there and restart the server to see what happens.

How are you getting things from the net? file_get_contents() or something else?

(On a side note it would be great if we could add in PHP modules or recompile PHP from scratch ... maybe I'll work on that next)

I have tried Try ini_set('max_execution_time', xxxx); to no avail.

Currently I am using wget to pull things down from the net, file_get_contents() to read in those files, and some sqlite database interactions to store information.

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
02-16-2009, 06:29 PM (This post was last modified: 02-16-2009 06:30 PM by Delphy.)
Post: #7
RE: PHP Script restart issue
file_get_contents in normal PHP can handle URL wrappers - the same applies to the one on the PCH. wget is really only handy if you want to grab sub-dirs and so on too.

Try replacing the wget call with just a straight file_get_contents("http://whereever"); - it should be quicker since it doesn't need to wait for a system call as per the wget.

Incidentally, are you using the sqlite3 wrappers in PHP? If so, which ones? The normal SQLite3() ones dont work for me.

My NMT apps / themes
Find all posts by this user
02-16-2009, 07:05 PM
Post: #8
RE: PHP Script restart issue
(02-16-2009 06:29 PM)Delphy Wrote:  file_get_contents in normal PHP can handle URL wrappers - the same applies to the one on the PCH. wget is really only handy if you want to grab sub-dirs and so on too.

Try replacing the wget call with just a straight file_get_contents("http://whereever"); - it should be quicker since it doesn't need to wait for a system call as per the wget.

Incidentally, are you using the sqlite3 wrappers in PHP? If so, which ones? The normal SQLite3() ones dont work for me.

Thanks. For the files I am just parsing I will convert over to file_get_contents and just use wget for the images I am downloading. Being a novice in php I don't think I am using the sqlite3 wrappers but here is a list of the command I use

Code:
sqlite_open
sqlite_close
sqlite_query

cmgrant

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
02-16-2009, 07:47 PM (This post was last modified: 02-16-2009 07:48 PM by Delphy.)
Post: #9
RE: PHP Script restart issue
Thanks - I'll have to check out those sqlite commands - I haven't touched that in a week or so though Smile

You can use file_get_contents() for image files too. Smile

Code:
$imageFile = file_get_contents("http://www.networkedmediatank.com/images/logo.gif");
$handle = fopen($saveImageName, "wb");
fwrite($handle, $imageFile);
fclose($handle);

My NMT apps / themes
Find all posts by this user
02-18-2009, 06:30 AM
Post: #10
RE: PHP Script restart issue
I have tested file_get_contents with websites and failed miserably. Currently I get two errors back. The first is: php_network_getaddresses: getaddrinfo failed and the second is: failed to open stream: Address family not supported by protocol

Any Idea whats causing this. Something as simple as
Code:
$filestring = file_get_contents("http://www.google.com");

does not even work. I can ping it from the telnet command line though

cmgrant

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
02-18-2009, 08:13 AM (This post was last modified: 02-18-2009 08:18 AM by journey4712.)
Post: #11
RE: PHP Script restart issue
The file_get_contents problem, basically as you see the php 4 that is installed in the NMT has a broken getaddrinfo() function. I dont know how to fix it exactly, but there is a way arround it.

The NMT has 2 versions of php on it, php4 and php5. files requested without any special setup are executed with php4 which has the problem.

To get your program interpreted with php5, which has a working implementation, you can either a) install the webserver 1.0.0 in the nmt community installer, then you can place files in .www/localhost and access them with http://ip-of-pch:8080/. b) Copy or symlink your files into /opt/sybhttpd/default/ and access them with http://ip-of-pch:8883/. You can only do that from the command line(telnet or editing start_app.sh to symlink a directory on boot(ln -s /share/myprog /opt/sybhttpd/default would make a link from the dir myprog on your harddrive to http://ip-of-pch:8883/myprog/)).

journey4712
Find all posts by this user
02-18-2009, 03:21 PM
Post: #12
RE: PHP Script restart issue
The broken PHP4 getaddrinfo is mostly becuase of the broken hostname setup on the PCH boxes. But journey is correct - you'd need to run another php5 webserver to make it work properly at the moment.

My NMT apps / themes
Find all posts by this user
02-18-2009, 04:48 PM
Post: #13
RE: PHP Script restart issue
Thanks both of you . I guess I'll have to spend some time looking both options.

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
02-18-2009, 05:04 PM (This post was last modified: 02-18-2009 05:08 PM by Delphy.)
Post: #14
RE: PHP Script restart issue
If you want to be able to use the inbuilt PCH browser/skin (ie gaya) to retrieve files via file_get_contents() then you can use this script to automatically grab a file. It still relys on the php5 webserver, but runs "transparently" to the normal PCH operations.

First, install the webserver (listening on whatever port...8080 or 8082 etc)

Next, put this script in the root of your webserver on the PCH (ie /share/.www). Call it getfile.php

Code:
<?php

if (!isset($_GET['url'])) { exit; }
if (!isset($_GET['file'])) { exit; }

$contents = file_get_contents($_GET['url']);

$handle = fopen("/share/".$_GET['file'], 'w');
fwrite($handle, $contents);
fclose($handle);

?>

(You may add error handling if you like... this is quick and dirty though so I left that as an exercise for the reader.) Note that it's hardcoded to put stuff into /share/ but you could change thing if you want.

Next, all you have to do is to call this from your normal PCH script like so:

Code:
file_get_contents("http://127.0.0.1:8082/getfile.php?url=http://www.networkedmediatank.com/images/logo.gif&file=.www/logo.gif");

Becuase it's a local URL, the file_get_contents will succeed and call the script located in your Apache/php5 webserver, which will then get the file using the normal file_get_contents();

It's inelegant, yes, but it works and is fairly transparent to your normal script.

Note you could even have the getfile.php script *not* automatically save the thing it's grabbing and instead just echo $contents, then have your calling script perform any file save operations etc. (This obviously would be better if you are grabbing HTML contents.)

To do this, modify getfile.php to the following:

Code:
<?php

if (!isset($_GET['url'])) { exit; }

echo file_get_contents($_GET['url']);

?>

Then just change your calling script to:

Code:
$contents = file_get_contents("http://127.0.0.1:8080/getfile.php?url=http://www.networkedmediatank.com/images/logo.gif");

Then you can act on $contents just like it was coming from a proper file_get_contents() call.


PS replace lt; and gt; with the proper php opening and closing tags Smile

My NMT apps / themes
Find all posts by this user
02-19-2009, 05:06 AM
Post: #15
RE: PHP Script restart issue
Here is a solution the I found that seems to be the easiest for deploying an application for use. It is a simple php5 call wrapped in a shell script.

Code:
#!/bin/sh

## PHP5 shell wrapper for PCH MNT
## Written by cmgrant

PHPCMD=""
if [ "$1" != "" ]; then
PHPCMD=`echo $1|sed 's/%20/ /g'`
/mnt/syb8634/server/php5-cgi $PHPCMD
fi
exit 0

and here is how it is invoked from another shell script through a link

Code:
echo '<TR><TD><A HREF="http://localhost.drives:8883/HARD_DISK/Video/DMJ/execute_php5.cgi?/opt/sybhttpd/localhost.drives/HARD_DISK/Video/DMJ/add_db.php dbname='$database' path='$scanpath'">'"$scanpath"
  echo "</TD></TR>"

Inside the real php script make sure to trim all the _GET parameters

cmgrant

"Your jambox is now his jambox by way of our actions."
cmgrant -[-at-]- gmail -[-dot-]- com
Find all posts by this user
Thread Closed 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Star [Apps] Bierdopje 4 NMT PHP script SilverViper 4 2,432 11-26-2012 04:57 PM
Last Post: Djiest
  /etc refreshed on restart jampot31 2 1,115 07-08-2012 03:28 AM
Last Post: jampot31
  DropBear ssh client - key auth issue serek 0 4,206 12-28-2011 01:05 AM
Last Post: serek
  Need help debugging a simple script to enable NTFS write on HDD user33 10 4,403 04-05-2011 06:05 PM
Last Post: nuke12
  Help with Server Timeout Error running a script hindibuff 0 2,156 03-29-2011 06:21 AM
Last Post: hindibuff
Bug Executing a script on the server from the NMT? johnk 6 4,149 02-21-2011 10:59 PM
Last Post: johnk
  Issue grabbing posters from themoviedb lordy 0 1,108 11-16-2010 04:18 PM
Last Post: lordy
  [AUDIO] lastfm script (bookmarks, auto-login, etc.) mk11 81 45,586 10-09-2010 01:45 AM
Last Post: opfeifer
Information A-100 Playon issue Fishing for ideas BudGreen 1 1,690 06-07-2010 07:16 PM
Last Post: MiniMe
  help with auto unrar script. kiranos 0 2,086 05-15-2010 10:24 AM
Last Post: kiranos

Forum Jump: