« first day (4486 days earlier)      last day (445 days later) » 

12:27 AM
@LeviMorrison Yes it is, the CData is a pointer array, and adding it moves the pointer forward to the [1] entry.
@azjezz You're going past the pointer array here
@LeviMorrison Well, yeah I could. I was reverse engineering this case by staring at which clases implement a do_operation handler, and learned the smallest amount of FFI to get this working
 
 
4 hours later…
4:14 AM
@Girgias Anyway, overall this looks good to me. I like consistency, and although it's a breaking change it's likely to be a helpful one (you were probably accidentally doing nonsense before).
 
 
11 hours later…
3:16 PM
any help with encrypting large inputs with OpenSSL extension in PHP is welcome: stackoverflow.com/questions/75260021/…
 
Generate a random symmetric key using random_bytes(), encrypt your data with that symmetric key. Encrypt the symmetric key with the public key and prepend the encrypted symmetric key to the symmetrically encrypted payload.
 
3:32 PM
Noice.
 
4:20 PM
Hi guys, is there an easy way to change values in an .ini config file?
 
With a text editor?
 
Funny. With PHP code.
 
You can set ini values from functions....aka what exactly are you trying to do?
 
If you want to edit the file directly, which I question, you could use the DBA extension with the "inifile" handler
 
4:27 PM
o/
 
\o
 
Yes, but is there an easy way without having to rewrite the entire file?
As in a native method or smth?
 
No
 
4:44 PM
\o
 
o/
 
\o
 
5:02 PM
\o/
 
5:23 PM
@Jerm. some of the config options, it depends on what the setting is though
ini_set() for some settings
 
I'm really torn on the extending readonly classes question. I can see the practical argument, but I also am very reticent about the "I can't trust it anymore" / LSP factor.
 
You can abstain...
 
I may.
 
cmb
@Jerm. You could use another php.ini file, in which case you won't have to modify the original.
 
5:39 PM
@azjezz I wonder how FFI could interact with my PHP-to-C transpiler :d
 
I don’t mean changing values in the php.ini file, but in a config .ini file I use in a project of mine.
 
I mean, you can write a parser in just about any language... but it's not going to be easy...
but there isn't going to be a function in PHP that modifies a singular value in an INI file, without rewriting the whole file
4
A: How to update an ini file with php?

mtolooI used the first suggestion of you: So would I use the parse_ini_file to get all of the infromation then make my changes and use fwrite to rewrite the whole file function config_set($config_file, $section, $key, $value) { $config_data = parse_ini_file($config_file, true); $config_d...

php.net/manual/en/book.parle.php might be another way, but this would be more cumbersome than using parse_ini_file
better question is...can you store those configuration settings in a file other than an ini file?
can they be stored inside a class as state?
can they be stored inside constants?
or even better 3v4l.org/E8U0T
 
 
2 hours later…
7:38 PM
Thanks for your answers. I want to store longer text.
 
7:49 PM
@Trowski Amphp question … in building a continuously running process that polls for data and keeps running even if there’s no data to process at the moment, it sounds like Revolt’s event loop on repeat() is not a good idea, but I’ve found Amphp’s pipeline, and could that work if the Generator I create yields a special “idle” object that the callback can use to decide to return without doing any work?
 
8:28 PM
the question is when do you pool the data? every X amout of time? in that case, EventLoop::repeat is good enough, you can have a in-memory channel where the callback in the event would send data via the channel, and have a consumer on the outside that waits for data in the channel and do Y with it.

you also want another callback for handling signals, and if invoked, cancels out the first callback.
 
8:49 PM
@ramsey Revolt's repeat() can work for that. Within the loop used to create a pipeline you could consider using delay(seconds, cancellation: new SignalCancellation(SIGTERM)).
 
@Jerm. yeah, longer text can be stored in memory inside a class... why is it being stored in an ini file?
 
9:14 PM
Is Jeeves the best chat bot (send/receive) for SE? github.com/Room-11
 
 
1 hour later…
10:43 PM
@azjezz You lost me on "channels" :-)
 
$pipeline = Pipeline::fromIterable(function () {
    yield from pollForEventsReturningArrayOfEvents();
    // Async sleep for 5 seconds before polling for more events.
    delay(5, cancellation: new SignalCancellation(SIGTERM));
});

try {
    foreach ($pipeline as $event) {
        // handle $event
    }
} catch (CancelledException) {
    // Received signal, exit.
}
 
@Trowski The docs on repeat() say "repeat() callbacks must be explicitly canceled to free associated resources. Failure to free repeat() callbacks via cancel() once their purpose is fulfilled will result in memory leaks in your application." So, I assumed that meant that you shouldn't keep it repeating.
And if you call EventLoop::cancel($callbackId); it shuts down the loop
 
No, that's just trying to say you need to remember to cancel a repeat callback once it is no longer needed. For example, a repeat callback on a cache object. If you destroy the cache object, you need to cancel the repeat callback.
 
I see
I wasn't sure if those callbacks kept stacking up and growing in memory, and maybe that's why it said that
 
There's nothing wrong with your entire application being one repeat callback.
 
10:49 PM
 
@JamesRisner Jeeves is outdated. Async Bot is a rewrite of Jeeves, but it's unfinished: github.com/async-bot
 
@ramsey You want to sleep for some time if the last poll for events was empty, correct? That should go into the generator.
 
@Trowski would I use an actual sleep() call, or one of the EventLoop methods for that?
 
@ramsey Amp\delay()
 
cool
 
10:57 PM
Polling for an event is blocking, right?
Pipeline will yield the last event, queuing it to be processed, but will immediately loop around to polling for events, which might block the processing.
 
@Trowski Ah, yeah. Gotcha
I was thinking of having it yield an "idle" event in those cases, so that it's not waiting
but would a delay be better?
 
What would your foreach callback do with the idle event? Call delay in that function?
 
@Trowski this is how I was thinking about it (updated the gist: gist.github.com/ramsey/582bea383bc9d1f31019da8546681953)
I put the delay(5) in there, but I was actually considering it without that, and just always returning some value that would indicate "idle"
In this case, it's -1
when the forEach gets that, it would just return without waiting
 
11:15 PM
@ramsey You don't have to yield at all there. Call delay only.
 
cool... so, the next time through the while() loop, if it still doesn't fetch any data, just call delay() again?
 
Exactly
 
Thanks!
 
@ramsey If I might suggest pushing the blocking polling to another process, keeping the main process completely non-blocking: gist.github.com/trowski/28c8fe782f70071691080ca3f9a8fda5
 
@Tiffany Thanks. I couldn’t find any read me or docs indicating what parts are unfinished. Do you know what it can’t yet do?
 
11:19 PM
@Trowski Perfect! Thanks so much!
 
@ramsey The caveat there is that events have to be serialized to send between processes.
 
Ah, gotcha... so... serialized, as in, __serialize() and __unserialize()?
 
@ramsey By default yes, though you can override that with JSON or any other strategy if you wish.
 
haha... I just ran into this because I used an anonymous class that couldn't be serialized :-)
 
lol, well that is presumably an easy fix :D
 
11:30 PM
Yeah. I'm just reworking my example so that it's not in two files, is all
 
Instances sent over the channel must be autoloadable by composer.
 
so, it's the tasks itself that are serialized?
 
Yes, the Task object needs to be autoloadable in the child process.
You can set serializable data in the constructor of your Task object, which will be available in the child when run() is invoked.
Here's an example of a Task implementation in amphp/file which is used to run blocking file ops in a child process: github.com/amphp/file/blob/…
A new instance of that class is sent to the child for each op. The op to be performed is given to the constructor in the parent. When run() is invoked in the child, it uses the object props to determine what to do.
 
@Tiffany Isn’t not storing config information in code best practice?
So that’s why I have an .ini for a config.
 
@Trowski Is there documentation on where TResult, TReceive, TSend, and TCache are used?
 
11:42 PM
@Jerm. it depends if the config contains a secret, in which case, it should be stored as an environment variable. Then accessed with $_ENV.
 
I see TResult is the response from run(), but that's all I know
 
@Tif
@Tiffany Yes, it contains API keys and other information, including said longer text
 
Any private/secret configuration should be an environment variable
 
Okay, right now it’s part of my config file. I will move it out. But how would you store longer text (500W+)?
 
It depends on how you intend to use it
There are too many factors... because you can store it in a text file, you can store it in a database, you can store it in cache, you can store it in memory...
 
11:47 PM
They are static and being sent frequently. Right now it’s loading it from the .ini file in an array which is then accessed by the code
 
I question the reasons why you're using an ini file to begin with, because it seems overcomplicated
There are use cases for an ini file
But they're limited
 
I do not only store text but also other values, and reading from an .ini file is quite easy with parse_ini_file(). Why is that complicated?
 
Again, depends on your use case
 
such as?
 
There are generally better ways to store the information
 
11:50 PM
Please specify
 
But again, there are use cases for ini
 
Well, it’s a config file that also contains messages
 
It has been 1+ years since I've encountered ini files in a PHP application, so I can't remember offhand
What kind of messages?
 
Messages sent to users, up to 500W. What do you use as config?
 
@Trowski What does "Channel source closed unexpectedly" mean?
 
11:53 PM
@Jerm. so static messages like errors?
 
@Jerm. Most use a PHP array as config, these days... you have config.php with something like: <?php return ['foo' => 'bar']; in it
and then you can do $config = require_once('config.php');, and that has your array in it
so, no need to do any INI file parsing :-)
 
Not errors, more like information.
@ramsey oh well, it’s just that I’ve been always told storing information in code is a bad practice because it doesn’t really allow non-coders to edit
 
What Ramsey said. I was laid off recently, so I can't remember how it was done offhand.
 
Thanks Tiffany
 
@Jerm. that's true, but we weren't aware that non-dev being able to modify the information was a requirement
You should've stated that ;)
 
11:57 PM
@Tiffany I mean it isn’t in this case, but I try to keep the code clean by using best practices
 
@ramsey TRecieve and TSend are on Channel, and TCache is for Cache. See the Task interface definition
 
But if you all say it doesn’t matter... storing all the messages in a php file sure would be easiest
 
@Trowski I see the docs on the interface now. For some reason, PhpStorm wasn't showing them to me properly
 
@ramsey In the parent from $channel->receive(). I guess it's because we're closing the channel in the child abruptly. You could send null as an indicator the channel is closing in the child, then end the loop in the parent when null is received.
 
@Jerm. Do you have non-coders who need to edit the config file?
 

« first day (4486 days earlier)      last day (445 days later) »