php-general Digest 21 Nov 2011 17:14:33 -0000 Issue 7579
Topics (messages 315780 through 315785):
Re: include
315780 by: Tommy Pham
315781 by: Tommy Pham
315782 by: Tim Streater
315783 by: Tommy Pham
315784 by: Tim Streater
Re: PHP script won't run in the background
315785 by: Richard Quadling
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On Sun, Nov 20, 2011 at 1:34 PM, Tim Streater <t...@clothears.org.uk> wrote:
> On 20 Nov 2011 at 10:36, Tommy Pham <tommy...@gmail.com> wrote:
>
>> I think you're approaching this the wrong way.
>> 1) have a clear understanding of PHP - syntax, capabilities, etc.
>
> That's what I'm doing - gathering information about bits of PHP that I've not
> used (or not used very much) before to see how my new setup could be
> structured.
>
That's a good starting point.
>> 2) have a clear understand of what you're intending to do -
>> application's function/purpose, features, manageability,
>> expandability, portability, etc...
>
> I have a clear idea about *that*. I want to figure out if it's possible to
> use web sockets with a small server written in PHP to replace my current
> structure of ajax + apache + processes (which I suppose it forks). I see
> these benefits:
>
> 1) possible benefit - presumably when an ajax request arrives, a new process
> is started and so PHP has to be loaded and initialised each time. But perhaps
> this is in some way optimised so the PHP process is left running and apache
> then just tells it to read/execute a new script.
>
> 2) Definite benefit - when a browser makes an ajax request to run a script,
> it gets no information back until the script completes. Then it gets all of
> it. I have a couple of unsatisfactory workarounds for that in my existing
> structure. Websockets appears to offer a way for the browser to receive
> timely information.
>
You didn't understand my 2nd point completely. The 2nd point starts
with what function/purpose does the app provide such as is it an
e-commerce, CMS, forum, etc... What you're talking about is the
process(es) which facilitate(s) the application's functions ie:
"there's more than one way to skin the cat" - so to speak. Which is
part of manageability, portability, expandability (ie: scaling to
clusters, ease of 3rd party plugins, etc), etc....
>> 3) understand design patterns
>
> I don't know what this means.
>
Google "programming design patterns"
>> What your asking is practically impossible in any programming language
>> akin to 'how to un-import packages in Java' or 'how to un-using
>> namespace in C#'. If you don't want to use it, don't include it ;)
>
> I do want to use it but would like to be able to replace it with a newer
> version. If there is no way to do this then that is a data point.
>
That's why I suggested you read up regarding OOP, including Interface
and Abstracts. In OOP, you define and guaranteed certain
functionalities with Interfaces - hence the term API (Application
Programming Interface) - but you pass a super/parent class or any of
its sub/child classes, implement those interface(s), to do the work
needed as how you want things done based on certain criteria. Classic
example:
1) connect to db
2) execute query
3) fetch results
4) process results
5) close connection
given those 5 above steps, there are many ways to proceed about it.
Which way you choose depends on my 2nd point. In the past, the
standard practice was using client library such as MySQL or MySQLi,
especially prior to PHP5. Now it's done via PDO or other data
abstraction layer, including ORM depending on a lot of things:
experience, skills, knowledge, project dead line, personal
preference/style, best coding practices, and lazyness in that given
moment - not particularly in those order either.
> And here's another question. Can a child forked by pcntl_fork() use a socket
> that the parent obtained? Reading the socket stuff in the PHP doc, there are
> a number of user-supplied notes hinting this might be problematic.
>
> --
> Cheers -- Tim
>
HTH,
Tommy
--- End Message ---
--- Begin Message ---
On Sun, Nov 20, 2011 at 4:44 PM, Tommy Pham <tommy...@gmail.com> wrote:
> On Sun, Nov 20, 2011 at 1:34 PM, Tim Streater <t...@clothears.org.uk> wrote:
>> On 20 Nov 2011 at 10:36, Tommy Pham <tommy...@gmail.com> wrote:
>>
>> And here's another question. Can a child forked by pcntl_fork() use a socket
>> that the parent obtained? Reading the socket stuff in the PHP doc, there are
>> a number of user-supplied notes hinting this might be problematic.
>>
>> --
>> Cheers -- Tim
>>
>
Forgot to address this in my previous e-mail because I was cooking
while trying to read/reply my e-mails. Anyway, if I'm not mistaken,
what you're trying to do is making a threaded application. PHP does
not support threads currently. PHP and threads has been a heated
discussion on this list in the past. You're welcome to search the
archives. [1]
HTH,
Tommy
[1] http://marc.info/?l=php-general
--- End Message ---
--- Begin Message ---
On 20 Nov 2011 at 23:46, Tamara Temple <tamouse.li...@tamaratemple.com> wrote:
> Tim Streater <t...@clothears.org.uk> wrote:
>
>> At the moment I'm using an instance of apache to run PHP scripts, as
>> and when required via AJAX. Having got some understanding of web
>> sockets, I'm minded to look at having a small server to execute these
>> functions as required. The scripts, some 50 or so, are only about
>> 300kbytes of source code, which seems small enough that it could all
>> be loaded with include, as in:
>
>> <?php
>> $fn = 'wiggy.php';
>> include $fn;
>> ?>
>>
>> This appears to work although I couldn't see it documented.
>
> I'm really not sure what you're looking for here -- that is pretty
> standard php practice to load php files with include -- what were you
> expecting here?
I'm looking for confirmation that:
include $fn;
is an allowed form of the include statement.
> While it's certainly possible to rig up something using sockets, I don't
> think that's how AJAX works, and you'd need a JS library that did.
Hmmm, I think perhaps I've not made myself clear - sorry about that. At present
I'm using AJAX and apache; I'd like to *stop* doing that (and not use another
web server, either). In my case, client and server are the same machine - the
user's machine. There is a browser window and JavaScript within it which makes
the AJAX requests. I just happen to use apache to have a variety of PHP scripts
run to provide results back to the browser window.
> Generally, you should only really need to dynamically replace parts of a
> long-running program if you don't want to restart it. However, php
> scripts are not long-running programs in general, unlike the apache
> server itself, for example, and certainly if the php scripts are running
> under apache, they will be time- and space-limited by whatever is set in
> the php.ini file. If these little scripts are merely responding to AJAX
> requests, they should be really short-lived.
At present these scripts generally are short-lived, but with some notable
exceptions. Hence my exploration of whether I could use websockets instead.
--
Cheers -- Tim
--- End Message ---
--- Begin Message ---
On Mon, Nov 21, 2011 at 2:56 AM, Tim Streater <t...@clothears.org.uk> wrote:
> On 20 Nov 2011 at 23:46, Tamara Temple <tamouse.li...@tamaratemple.com> wrote:
>
>> Tim Streater <t...@clothears.org.uk> wrote:
>>
>>> At the moment I'm using an instance of apache to run PHP scripts, as
>>> and when required via AJAX. Having got some understanding of web
>>> sockets, I'm minded to look at having a small server to execute these
>>> functions as required. The scripts, some 50 or so, are only about
>>> 300kbytes of source code, which seems small enough that it could all
>>> be loaded with include, as in:
>>
>>> <?php
>>> $fn = 'wiggy.php';
>>> include $fn;
>>> ?>
>>>
>>> This appears to work although I couldn't see it documented.
>>
>> I'm really not sure what you're looking for here -- that is pretty
>> standard php practice to load php files with include -- what were you
>> expecting here?
>
> I'm looking for confirmation that:
>
> include $fn;
>
> is an allowed form of the include statement.
>
RTFM [1] example #6 ;)
HTH,
Tommy
[1] http://php.net/function.include
--- End Message ---
--- Begin Message ---
On 21 Nov 2011 at 11:10, Tommy Pham <tommy...@gmail.com> wrote:
> On Mon, Nov 21, 2011 at 2:56 AM, Tim Streater <t...@clothears.org.uk> wrote:
>> I'm looking for confirmation that:
>>
>> include $fn;
>>
>> is an allowed form of the include statement.
>>
>
> RTFM [1] example #6 ;)
> [1] http://php.net/function.include
Thanks - I missed that one.
--
Cheers -- Tim
--- End Message ---
--- Begin Message ---
On 19 November 2011 14:33, richard gray <r...@richgray.com> wrote:
> Hi all
>
> Hope someone can help me with a weird issue I have...
>
> I am trying to run a php CLI script in the background and it just won't run
> - it has a status of Stopped SIGTOU (Trying to write output) - Here are the
> details
>
> OS
> Mac OS X Lion 10.7.2
>
> PHP
> PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep 8 2011 19:34:00)
> Copyright (c) 1997-2011 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
>
> I created a basic script test.php
>
> <?php echo 'Hello world'.PHP_EOL; ?>
>
> Here are the results of various tests:-
>
> Test 1) php -f test.php (Hello world gets displayed)
> Test 2) php -f test.php >test.log 2>&1 (Hello world gets put into test.log)
> Test 3) php -f test.php >test.log 2>&1 & --- I get [1]+ Stopped(SIGTTOU)
> php -f test.php > test.log 2>&1 -- and the job just sits there doing
> nothing nothing gets logged however lsof shows the log file is open
>
> It is something to do with php because a similar shell script gets executed
> no problems in the background...
>
> This has me stumped ... any ideas?
>
> TIA
> Rich
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I've seen this ...
php script.php 1>nul 2>nul
Not sure how effective it is. But the code is tagged as a "fire and
forget" mechanism.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc : Fantasy Shopper
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea :
fan.sh/6/370
--- End Message ---