Re: command line tool called from php
Re: command line tool called from php
- Subject: Re: command line tool called from php
- From: Daniel Acosta <email@hidden>
- Date: Tue, 23 Aug 2011 01:19:25 -0700
On Aug 23, 2011, at 12:15 AM, Jens Alfke wrote:
>
> On Aug 22, 2011, at 10:45 PM, Rainer Standke wrote:
>
>> I have a command line tool that uses foundation. When I run that tool from the command line it does what I need it to do. This includes sending an NSNotification to a Cocoa application via the NSDistributedNotificationCenter.
>>
>> When I call the same command line tool from a php page served by Apache on the same machine, the notification is never sent.
I'm new to Cocoa and I may be wrong here but this got me curious.
>
> Apache isn’t running in the same login context as your app. In fact it’s an entirely separate user account. Distributed notifications don’t go between login sessions.
That last bit gave me the clue and found the solution in the documentation for NSDistributedNotificationCenter.
I just made a test using -postNotificationName:object:userInfo:options: passing under options NSNotificationPostToAllSessions and it worked like a charm, though I don't know if this is considered best practice.
(http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSNotificationPostToAllSessions)
>
> I can’t think of any straightforward solution. Probably the best approach is to have your Cocoa app listen on an IP port and then the tool can send a message to that port. You’d have to either hardcode the port number or find a way to communicate the number to the tool, and the app would need to make sure it binds only to the loopback interface to avoid the possibility of getting pinged by another machine.
>
> —Jens_______________________________________________
You may also want to double-check permissions on your command line tool, to make sure Apache (I believe by default it runs under user _www) can actually read and execute it.
Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden